summaryrefslogtreecommitdiff
path: root/xmlsecurity/source
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
parent8c7c9465b6a35c829294a829cfc3152e5dc9ce6e (diff)
libxmlsec
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx123
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.hxx94
-rw-r--r--xmlsecurity/source/component/makefile.mk86
-rw-r--r--xmlsecurity/source/component/registerservices.cxx135
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.cxx216
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.src125
-rw-r--r--xmlsecurity/source/dialogs/certificateviewer.cxx397
-rw-r--r--xmlsecurity/source/dialogs/certificateviewer.src334
-rw-r--r--xmlsecurity/source/dialogs/dialogs.hrc263
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx545
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.src159
-rw-r--r--xmlsecurity/source/dialogs/makefile.mk100
-rw-r--r--xmlsecurity/source/dialogs/resourcemanager.cxx190
-rw-r--r--xmlsecurity/source/dialogs/resourcemanager.hxx96
-rw-r--r--xmlsecurity/source/dialogs/stbcontrl.cxx232
-rw-r--r--xmlsecurity/source/framework/buffernode.cxx1313
-rw-r--r--xmlsecurity/source/framework/buffernode.hxx175
-rw-r--r--xmlsecurity/source/framework/decryptorimpl.cxx288
-rw-r--r--xmlsecurity/source/framework/decryptorimpl.hxx176
-rw-r--r--xmlsecurity/source/framework/elementcollector.cxx330
-rw-r--r--xmlsecurity/source/framework/elementcollector.hxx147
-rw-r--r--xmlsecurity/source/framework/elementmark.cxx136
-rw-r--r--xmlsecurity/source/framework/elementmark.hxx123
-rw-r--r--xmlsecurity/source/framework/encryptionengine.cxx254
-rw-r--r--xmlsecurity/source/framework/encryptionengine.hxx157
-rw-r--r--xmlsecurity/source/framework/encryptorimpl.cxx328
-rw-r--r--xmlsecurity/source/framework/encryptorimpl.hxx190
-rw-r--r--xmlsecurity/source/framework/makefile.mk98
-rw-r--r--xmlsecurity/source/framework/saxeventkeeperimpl.cxx1503
-rw-r--r--xmlsecurity/source/framework/saxeventkeeperimpl.hxx423
-rw-r--r--xmlsecurity/source/framework/securityengine.cxx122
-rw-r--r--xmlsecurity/source/framework/securityengine.hxx225
-rw-r--r--xmlsecurity/source/framework/signaturecreatorimpl.cxx343
-rw-r--r--xmlsecurity/source/framework/signaturecreatorimpl.hxx189
-rw-r--r--xmlsecurity/source/framework/signatureengine.cxx306
-rw-r--r--xmlsecurity/source/framework/signatureengine.hxx199
-rw-r--r--xmlsecurity/source/framework/signatureverifierimpl.cxx288
-rw-r--r--xmlsecurity/source/framework/signatureverifierimpl.hxx175
-rw-r--r--xmlsecurity/source/framework/xmlencryptiontemplateimpl.cxx164
-rw-r--r--xmlsecurity/source/framework/xmlencryptiontemplateimpl.hxx168
-rw-r--r--xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx193
-rw-r--r--xmlsecurity/source/framework/xmlsignaturetemplateimpl.hxx177
-rw-r--r--xmlsecurity/source/framework/xsec_framework.cxx284
-rw-r--r--xmlsecurity/source/helper/makefile.mk90
-rw-r--r--xmlsecurity/source/helper/xmlsignaturehelper.cxx424
-rw-r--r--xmlsecurity/source/helper/xmlsignaturehelper2.cxx242
-rw-r--r--xmlsecurity/source/helper/xmlsignaturehelper2.hxx164
-rw-r--r--xmlsecurity/source/helper/xsecctl.cxx1359
-rw-r--r--xmlsecurity/source/helper/xsecctl.hxx580
-rw-r--r--xmlsecurity/source/helper/xsecparser.cxx353
-rw-r--r--xmlsecurity/source/helper/xsecparser.hxx199
-rw-r--r--xmlsecurity/source/helper/xsecsign.cxx394
-rw-r--r--xmlsecurity/source/helper/xsecverify.cxx349
-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
93 files changed, 27177 insertions, 0 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
new file mode 100644
index 000000000000..d000b23a33bd
--- /dev/null
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -0,0 +1,123 @@
+/*************************************************************************
+ *
+ * $RCSfile: documentdigitalsignatures.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 <documentdigitalsignatures.hxx>
+#include <xmlsecurity/digitalsignaturesdialog.hxx>
+
+#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
+#include <com/sun/star/embed/XStorage.hpp>
+#endif
+
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star;
+
+
+DocumentDigitalSignatures::DocumentDigitalSignatures( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory> rxMSF )
+{
+ mxMSF = rxMSF;
+}
+
+
+sal_Bool DocumentDigitalSignatures::SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, const ::rtl::OUString& rStorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException)
+{
+ DigitalSignaturesDialog aSignaturesDialog( NULL, mxMSF, SignatureModeDocumentContent );
+
+ bool bInit = aSignaturesDialog.Init( rTokenName );
+
+ DBG_ASSERT( bInit, "Error initializing security context!" );
+ if ( bInit )
+ {
+ aSignaturesDialog.SetStorage( rxStorage );
+ aSignaturesDialog.SetSignatureFileName( rStorageName );
+ aSignaturesDialog.Execute();
+ }
+
+ return 0;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > DocumentDigitalSignatures::VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > aInfos;
+ return aInfos;
+}
+
+rtl::OUString DocumentDigitalSignatures::GetImplementationName() throw (uno::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) );
+}
+
+uno::Sequence< rtl::OUString > SAL_CALL DocumentDigitalSignatures::GetSupportedServiceNames() throw (cssu::RuntimeException)
+{
+ uno::Sequence < rtl::OUString > aRet(1);
+ rtl::OUString* pArray = aRet.getArray();
+ pArray[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) );
+ return aRet;
+}
+
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL DocumentDigitalSignatures_CreateInstance(
+ const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr) throw ( com::sun::star::uno::Exception )
+{
+ return (cppu::OWeakObject*) new DocumentDigitalSignatures( rSMgr );
+}
+
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx
new file mode 100644
index 000000000000..50d10ad85084
--- /dev/null
+++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * $RCSfile: documentdigitalsignatures.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 _XMLSECURITY_DOCUMENTDIGITALSIGNATURES_HXX
+#define _XMLSECURITY_DOCUMENTDIGITALSIGNATURES_HXX
+
+#include <cppuhelper/implbase1.hxx>
+
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+
+
+class DocumentDigitalSignatures : public cppu::WeakImplHelper1
+<
+ com::sun::star::security::XDocumentDigitalSignatures
+>
+{
+private:
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF;
+
+public:
+ DocumentDigitalSignatures( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory> rxMSF );
+
+ // for service registration...
+ static ::rtl::OUString GetImplementationName() throw (com::sun::star::uno::RuntimeException);
+ static ::com::sun::star::uno::Sequence < ::rtl::OUString > GetSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
+
+ // XDocumentDigitalSignatures
+ virtual sal_Bool SAL_CALL SignDocumentContent( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignaturesInformation > SAL_CALL VerifyDocumentContentSignatures( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage, const ::rtl::OUString& StorageName, const ::rtl::OUString& rTokenName ) throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL DocumentDigitalSignatures_CreateInstance(
+ const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr) throw ( com::sun::star::uno::Exception );
+
+#endif // _XMLSECURITY_DOCUMENTDIGITALSIGNATURES_HXX
diff --git a/xmlsecurity/source/component/makefile.mk b/xmlsecurity/source/component/makefile.mk
new file mode 100644
index 000000000000..b25ed052d35e
--- /dev/null
+++ b/xmlsecurity/source/component/makefile.mk
@@ -0,0 +1,86 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+#
+# 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=component
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+# --- Files --------------------------------------------------------
+
+SLOFILES= \
+ $(SLO)$/documentdigitalsignatures.obj \
+ $(SLO)$/registerservices.obj \
+
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/component/registerservices.cxx b/xmlsecurity/source/component/registerservices.cxx
new file mode 100644
index 000000000000..43c4260b187a
--- /dev/null
+++ b/xmlsecurity/source/component/registerservices.cxx
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * $RCSfile: registerservices.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 <tools/debug.hxx>
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#include <cppuhelper/factory.hxx>
+
+
+#include <documentdigitalsignatures.hxx>
+
+using namespace ::com::sun::star;
+
+extern "C"
+{
+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 )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ sal_Int32 nPos = 0;
+ uno::Reference< registry::XRegistryKey > xNewKey(
+ reinterpret_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( DocumentDigitalSignatures::GetImplementationName() ) );
+ xNewKey = xNewKey->createKey( rtl::OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+ const uno::Sequence< rtl::OUString >& rSNL = DocumentDigitalSignatures::GetSupportedServiceNames();
+ const rtl::OUString* pArray = rSNL.getConstArray();
+ for ( nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (registry::InvalidRegistryException &)
+ {
+ DBG_ERROR( "InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+void* SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void* pRet = NULL;
+
+ //Decryptor
+ rtl::OUString implName = rtl::OUString::createFromAscii( pImplName );
+ if ( pServiceManager && implName.equals( DocumentDigitalSignatures::GetImplementationName() ) )
+ {
+ uno::Reference< lang::XSingleServiceFactory > xFactory( cppu::createSingleFactory(
+ reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ),
+ rtl::OUString::createFromAscii( pImplName ),
+ DocumentDigitalSignatures_CreateInstance, DocumentDigitalSignatures::GetSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+ return pRet;
+}
+
+} // extern "C"
+
+
+
+
+
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx
new file mode 100644
index 000000000000..efab9b3143e1
--- /dev/null
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -0,0 +1,216 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificatechooser.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 <xmlsecurity/certificatechooser.hxx>
+#include <xmlsecurity/certificateviewer.hxx>
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XSECURITYENVIRONMENT_HPP_
+#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
+#endif
+
+#ifndef _COMPHELPER_SEQUENCE_HXX_
+#include <comphelper/sequence.hxx>
+#endif
+
+// MM : added for password exception
+#include <vcl/msgbox.hxx>
+#include <com/sun/star/security/NoPasswordException.hpp>
+using namespace ::com::sun::star::security;
+
+// Only for bigIntegerToNumericString
+#include <xmlsecurity/xmlsignaturehelper.hxx>
+
+#include "dialogs.hrc"
+#include "resourcemanager.hxx"
+
+/* HACK: disable some warnings for MS-C */
+#ifdef _MSC_VER
+#pragma warning (disable : 4355) // 4355: this used in initializer-list
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star;
+
+#define INVAL_SEL 0xFFFF
+
+
+USHORT CertificateChooser::GetSelectedEntryPos( void ) const
+{
+ USHORT nSel = INVAL_SEL;
+
+ SvLBoxEntry* pSel = maCertLB.FirstSelected();
+ if( pSel )
+ nSel = ( USHORT ) pSel->GetUserData();
+
+ return nSel;
+}
+
+CertificateChooser::CertificateChooser( Window* _pParent, uno::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment, const SignatureInformations& _rCertsToIgnore )
+ :ModalDialog ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTCHOOSER ) )
+ ,maHintFT ( this, ResId( FT_HINT_SELECT ) )
+ ,maCertLB ( this, ResId( LB_SIGNATURES ) )
+ ,maViewBtn ( this, ResId( BTN_VIEWCERT ) )
+ ,maBottomSepFL ( this, ResId( FL_BOTTOM_SEP ) )
+ ,maOKBtn ( this, ResId( BTN_OK ) )
+ ,maCancelBtn ( this, ResId( BTN_CANCEL ) )
+ ,maHelpBtn ( this, ResId( BTN_HELP ) )
+{
+ static long nTabs[] = { 3, 0, 30*CS_LB_WIDTH/100, 60*CS_LB_WIDTH/100 };
+ maCertLB.SetTabs( &nTabs[0] );
+ maCertLB.InsertHeaderEntry( String( ResId( STR_HEADERBAR ) ) );
+
+ FreeResource();
+
+ mxSecurityEnvironment = _rxSecurityEnvironment;
+
+
+ maCertLB.SetSelectHdl( LINK( this, CertificateChooser, CertificateHighlightHdl ) );
+ maCertLB.SetDoubleClickHdl( LINK( this, CertificateChooser, CertificateSelectHdl ) );
+
+ // MM : added for password exception
+ try
+ {
+ maCerts = mxSecurityEnvironment->getPersonalCertificates();
+ }
+ catch (NoPasswordException&)
+ {
+ InfoBox( this, rtl::OUString( String( RTL_CONSTASCII_USTRINGPARAM( "No password is provided!\n\n" ) ) ) ).Execute();
+ }
+
+ sal_Int32 nCertificates = maCerts.getLength();
+ sal_Int32 nCertificatesToIgnore = _rCertsToIgnore.size();
+ if( nCertificatesToIgnore )
+ {
+ for( sal_Int32 nCert = nCertificates; nCert; )
+ {
+ uno::Reference< security::XCertificate > xCert = maCerts[ --nCert ];
+ int nCertsToIgnore = _rCertsToIgnore.size();
+ for( sal_Int32 nSig = 0; nSig < nCertificatesToIgnore; ++nSig )
+ {
+ const SignatureInformation& rInf = _rCertsToIgnore[ nSig ];
+ if( ( xCert->getIssuerName() == rInf.ouX509IssuerName ) && ( bigIntegerToNumericString( xCert->getSerialNumber() ) == rInf.ouX509SerialNumber ) )
+ {
+ ::comphelper::removeElementAt( maCerts, nCert );
+ }
+ }
+ }
+ nCertificates = maCerts.getLength();
+ }
+
+ String aCN_Id( String::CreateFromAscii( "CN" ) );
+
+ for( sal_Int32 nC = 0; nC < nCertificates; ++nC )
+ {
+ String aSubject ( XmlSec::GetContentPart( maCerts[ nC ]->getSubjectName(), aCN_Id ) );
+ String aDateTimeStr( XmlSec::GetDateString( maCerts[ nC ]->getNotAfter() ) );
+ String aIssuer ( XmlSec::GetContentPart( maCerts[ nC ]->getIssuerName(), aCN_Id ) );
+
+ SvLBoxEntry* pEntry = maCertLB.InsertEntry( aSubject );
+ maCertLB.SetEntryText( aIssuer, pEntry, 1 );
+ maCertLB.SetEntryText( aDateTimeStr, pEntry, 2 );
+ pEntry->SetUserData( ( void* ) nC ); // missuse user data as index
+ }
+
+ maViewBtn.SetClickHdl( LINK( this, CertificateChooser, ViewButtonHdl ) );
+ maViewBtn.Disable();
+}
+
+CertificateChooser::~CertificateChooser()
+{
+}
+
+uno::Reference< dcss::security::XCertificate > CertificateChooser::GetSelectedCertificate()
+{
+ uno::Reference< dcss::security::XCertificate > xCert;
+ USHORT nSelected = GetSelectedEntryPos();
+ if( nSelected < maCerts.getLength() )
+ xCert = maCerts[ nSelected ];
+
+ return xCert;
+}
+
+IMPL_LINK( CertificateChooser, CertificateHighlightHdl, void*, EMPTYARG )
+{
+ maViewBtn.Enable();
+ return 0;
+}
+
+IMPL_LINK( CertificateChooser, CertificateSelectHdl, void*, EMPTYARG )
+{
+ EndDialog( 1 );
+ return 0;
+}
+
+IMPL_LINK( CertificateChooser, ViewButtonHdl, Button*, EMPTYARG )
+{
+ ImplShowCertificateDetails();
+ return 0;
+}
+
+void CertificateChooser::ImplShowCertificateDetails()
+{
+ uno::Reference< dcss::security::XCertificate > xCert = GetSelectedCertificate();
+ if( xCert.is() )
+ {
+ CertificateViewer aViewer( this, mxSecurityEnvironment, xCert );
+ aViewer.Execute();
+ }
+} \ No newline at end of file
diff --git a/xmlsecurity/source/dialogs/certificatechooser.src b/xmlsecurity/source/dialogs/certificatechooser.src
new file mode 100644
index 000000000000..9431a3405608
--- /dev/null
+++ b/xmlsecurity/source/dialogs/certificatechooser.src
@@ -0,0 +1,125 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificatechooser.src,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "dialogs.hrc"
+
+ModalDialog RID_XMLSECDLG_CERTCHOOSER
+{
+// HelpId = HID_XMLSECDLG_CERTCHOOSER;
+ Size = MAP_APPFONT( CS_WIDTH, CS_HEIGHT );
+ OutputSize = TRUE;
+ Closeable = TRUE;
+ Moveable = TRUE;
+ SVLook = TRUE;
+
+// Text = "Zertifikat auswhlen";
+ Text = "Select Certificate";
+ Text [ en-US ] = "Select Certificate";
+
+ FixedText FT_HINT_SELECT
+ {
+ Pos = MAP_APPFONT( CS_COL_0, CS_ROW_0 );
+ Size = MAP_APPFONT( CS_COL_2-CS_COL_0, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Select the certificate you want to use for signing";
+ Text [ en-US ] = "Select the certificate you want to use for signing";
+ };
+ Control LB_SIGNATURES
+ {
+ Pos = MAP_APPFONT( CS_COL_0, CS_ROW_1 );
+ Size = MAP_APPFONT( CS_LB_WIDTH, CS_ROW_2-CS_ROW_1 );
+ SVLook = TRUE;
+ Border = TRUE;
+ };
+ String STR_HEADERBAR
+ {
+ Text = "Issued to\tIssued by\tExpiration Date";
+ Text [ en-US ] = "Issued to\tIssued by\tExpiration Date";
+ };
+ PushButton BTN_VIEWCERT
+ {
+ Pos = MAP_APPFONT( CS_COL_1, CS_ROW_3 );
+ Size = MAP_APPFONT( CS_COL_2-CS_COL_1, RSC_CD_PUSHBUTTON_HEIGHT );
+// Text = "Zertifikat anzeigen...";
+ Text = "View Certificate...";
+ Text [ en-US ] = "View Certificate...";
+ };
+ FixedLine FL_BOTTOM_SEP
+ {
+ Pos = MAP_APPFONT( 0, DLGS_BOTTOM_FL_Y( CS_HEIGHT ) );
+ Size = MAP_APPFONT( CS_WIDTH, RSC_CD_FIXEDLINE_HEIGHT );
+ };
+ OKButton BTN_OK
+ {
+ DefButton = TRUE;
+ Pos = MAP_APPFONT( DLGS_BOTTOM_OK_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+ CancelButton BTN_CANCEL
+ {
+ Pos = MAP_APPFONT( DLGS_BOTTOM_CANCEL_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+ HelpButton BTN_HELP
+ {
+ Pos = MAP_APPFONT( DLGS_BOTTOM_HELP_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+};
diff --git a/xmlsecurity/source/dialogs/certificateviewer.cxx b/xmlsecurity/source/dialogs/certificateviewer.cxx
new file mode 100644
index 000000000000..1d106bc4f51b
--- /dev/null
+++ b/xmlsecurity/source/dialogs/certificateviewer.cxx
@@ -0,0 +1,397 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificateviewer.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 <xmlsecurity/certificateviewer.hxx>
+
+// Only for bigIntegerToNumericString
+#include <xmlsecurity/xmlsignaturehelper.hxx>
+
+
+#ifndef _COM_SUN_STAR_SECURITY_XCERTIFICATE_HPP_
+#include <com/sun/star/security/XCertificate.hpp>
+#endif
+
+#include "dialogs.hrc"
+#include "resourcemanager.hxx"
+
+/* HACK: disable some warnings for MS-C */
+#ifdef _MSC_VER
+#pragma warning (disable : 4355) // 4355: this used in initializer-list
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star;
+
+
+namespace
+{
+ void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nXOffset = 0 );
+
+ void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nOffs )
+ {
+ long nWidth = _rCtrl.GetTextWidth( _rCtrl.GetText() );
+ Size aSize( _rCtrl.GetSizePixel() );
+ nWidth += _nOffs;
+ aSize.Width() = nWidth;
+ _rCtrl.SetPosPixel( _rStartIn_EndOut );
+ _rCtrl.SetSizePixel( aSize );
+ _rStartIn_EndOut.X() += nWidth;
+ }
+};
+
+CertificateViewer::CertificateViewer(
+ Window* _pParent,
+ cssu::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment,
+ cssu::Reference< dcss::security::XCertificate >& _rXCert )
+ :TabDialog ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTVIEWER ) )
+ ,maTabCtrl ( this, ResId( 1 ) )
+ ,maOkBtn ( this, ResId( BTN_OK ) )
+ ,maHelpBtn ( this, ResId( BTN_HELP ) )
+{
+ FreeResource();
+
+ mxSecurityEnvironment = _rxSecurityEnvironment;
+ mxCert = _rXCert;
+
+ maTabCtrl.SetTabPage( RID_XMLSECTP_GENERAL, new CertificateViewerGeneralTP( &maTabCtrl, this ) );
+ maTabCtrl.SetTabPage( RID_XMLSECTP_DETAILS, new CertificateViewerDetailsTP( &maTabCtrl, this ) );
+ maTabCtrl.SetTabPage( RID_XMLSECTP_CERTPATH, new CertificateViewerCertPathTP( &maTabCtrl, this ) );
+ maTabCtrl.SetCurPageId( RID_XMLSECTP_GENERAL );
+}
+
+CertificateViewer::~CertificateViewer()
+{
+ delete maTabCtrl.GetTabPage( RID_XMLSECTP_CERTPATH );
+ delete maTabCtrl.GetTabPage( RID_XMLSECTP_DETAILS );
+ delete maTabCtrl.GetTabPage( RID_XMLSECTP_GENERAL );
+}
+
+CertificateViewerTP::CertificateViewerTP( Window* _pParent, const ResId& _rResId, CertificateViewer* _pDlg )
+ :TabPage ( _pParent, _rResId )
+ ,mpDlg ( _pDlg )
+{
+}
+
+
+CertificateViewerGeneralTP::CertificateViewerGeneralTP( Window* _pParent, CertificateViewer* _pDlg )
+ :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_GENERAL ), _pDlg )
+ ,maFrameWin ( this, ResId( WIN_FRAME ) )
+ ,maCertImg ( this, ResId( IMG_CERT ) )
+ ,maCertInfoFI ( this, ResId( FI_CERTINFO ) )
+ ,maSep1FL ( this, ResId( FL_SEP1 ) )
+ ,maHintNotTrustedFI ( this, ResId( FI_HINTNOTTRUST ) )
+ ,maSep2FL ( this, ResId( FL_SEP2 ) )
+ ,maIssuedToLabelFI ( this, ResId( FI_ISSTOLABEL ) )
+ ,maIssuedToFI ( this, ResId( FI_ISSTO ) )
+ ,maIssuedByLabelFI ( this, ResId( FI_ISSBYLABEL ) )
+ ,maIssuedByFI ( this, ResId( FI_ISSBY ) )
+ ,maValidFromLabelFI ( this, ResId( FI_VALFROMLABEL ) )
+ ,maValidFromFI ( this, ResId( FI_VALFROM ) )
+ ,maValidToLabelFI ( this, ResId( FI_VALTOLABEL ) )
+ ,maValidToFI ( this, ResId( FI_VALTO ) )
+ ,maKeyImg ( this, ResId( IMG_KEY ) )
+ ,maHintCorrespPrivKeyFI ( this, ResId( FI_CORRPRIVKEY ) )
+{
+ FreeResource();
+
+ Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
+
+ maFrameWin.SetBackground( aBack );
+ maCertInfoFI.SetBackground( aBack );
+ maSep1FL.SetBackground( aBack );
+ maHintNotTrustedFI.SetBackground( aBack );
+ maSep2FL.SetBackground( aBack );
+ maIssuedToLabelFI.SetBackground( aBack );
+ maIssuedToFI.SetBackground( aBack );
+ maIssuedByLabelFI.SetBackground( aBack );
+ maIssuedByFI.SetBackground( aBack );
+ maValidFromLabelFI.SetBackground( aBack );
+ maValidFromFI.SetBackground( aBack );
+ maValidToLabelFI.SetBackground( aBack );
+ maValidToFI.SetBackground( aBack );
+ maKeyImg.SetBackground( aBack );
+ maHintCorrespPrivKeyFI.SetBackground( aBack );
+
+ // make some bold
+ Font aFnt( maCertInfoFI.GetFont() );
+ aFnt.SetWeight( WEIGHT_BOLD );
+ maCertInfoFI.SetFont( aFnt );
+ maHintNotTrustedFI.SetFont( aFnt );
+ maIssuedToLabelFI.SetFont( aFnt );
+ maIssuedByLabelFI.SetFont( aFnt );
+ maValidFromLabelFI.SetFont( aFnt );
+ maValidToLabelFI.SetFont( aFnt );
+
+ // insert data
+ cssu::Reference< dcss::security::XCertificate > xCert = mpDlg->mxCert;
+
+ String aCN_Id( String::CreateFromAscii( "CN" ) );
+
+ maIssuedToFI.SetText( XmlSec::GetContentPart( xCert->getSubjectName(), aCN_Id ) );
+ maIssuedByFI.SetText( XmlSec::GetContentPart( xCert->getIssuerName(), aCN_Id ) );
+ maValidFromFI.SetText( XmlSec::GetDateString( xCert->getNotBefore() ) );
+ maValidToFI.SetText( XmlSec::GetDateString( xCert->getNotAfter() ) );
+
+ // recalc positions for date fields according to real size
+ Point aPos( maValidFromLabelFI.GetPosPixel() );
+// long nWidth;
+
+// nWidth = GetTextWidth( maValidFromLabelFI.GetText() );
+// maValidFromLabelFI.SetSizePixel
+// aPos.X() += nWidth;
+ AdjustPosAndSize( maValidFromLabelFI, aPos );
+
+// maValidFromFI.SetPosPixel( aPos );
+// nWidth = GetTextWidth( maValidFromFI.GetText() );
+// aPos.X() += nWidth;
+ AdjustPosAndSize( maValidFromFI, aPos );
+
+// maValidToLabelFI.SetPosPixel( aPos );
+// nWidth = GetTextWidth( maValidToLabelFI.GetText() );
+// aPos.X() += nWidth;
+
+// maValidToFI.SetPosPixel( aPos );
+ AdjustPosAndSize( maValidToLabelFI, aPos );
+ AdjustPosAndSize( maValidToFI, aPos );
+
+ // adjust position of fixed text depending on image sizes
+ long nWidth = maCertImg.GetSizePixel().Width();
+ aPos = maCertInfoFI.GetPosPixel();
+ aPos.X() = maCertImg.GetPosPixel().X();
+ aPos.X() += nWidth;
+ maCertInfoFI.SetPosPixel( aPos );
+
+ nWidth = maKeyImg.GetSizePixel().Width();
+ aPos = maHintCorrespPrivKeyFI.GetPosPixel();
+ aPos.X() = maKeyImg.GetPosPixel().X();
+ aPos.X() += nWidth;
+// maHintCorrespPrivKeyFI.SetPosPixel( aPos );
+ AdjustPosAndSize( maHintCorrespPrivKeyFI, aPos );
+}
+
+void CertificateViewerGeneralTP::ActivatePage()
+{
+}
+
+
+void CertificateViewerDetailsTP::Clear( void )
+{
+ maElementML.SetText( String() );
+ ULONG i = 0;
+ SvLBoxEntry* pEntry = maElementsLB.GetEntry( i );
+ while( pEntry )
+ {
+ delete ( String* ) pEntry->GetUserData();
+ ++i;
+ pEntry = maElementsLB.GetEntry( i );
+ }
+
+ maElementsLB.Clear();
+}
+
+void CertificateViewerDetailsTP::InsertElement( const String& _rField, const String& _rValue, const String& _rDetails )
+{
+ SvLBoxEntry* pEntry = maElementsLB.InsertEntry( _rField );
+ maElementsLB.SetEntryText( _rValue, pEntry, 1 );
+ pEntry->SetUserData( ( void* ) new String( _rDetails ) ); // extended view of value
+// pEntry->SetUserData( ( void* ) new String( XmlSec::GetPureContent( _rValue, "\n", true ) ) );
+}
+
+CertificateViewerDetailsTP::CertificateViewerDetailsTP( Window* _pParent, CertificateViewer* _pDlg )
+ :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_DETAILS ), _pDlg )
+ ,maElementsLB ( this, ResId( LB_ELEMENTS ) )
+ ,maElementML ( this, ResId( ML_ELEMENT ) )
+{
+ static long nTabs[] = { 2, 0, 40*CS_LB_WIDTH/100 };
+ maElementsLB.SetTabs( &nTabs[ 0 ] );
+ maElementsLB.InsertHeaderEntry( String( ResId( STR_HEADERBAR ) ) );
+
+ // fill list box
+ Reference< security::XCertificate > xCert = mpDlg->mxCert;
+ String aLBEntry;
+ String aDetails;
+ aLBEntry = aDetails = String::CreateFromInt32( xCert->getVersion() );
+ InsertElement( String( ResId( STR_VERSION ) ), aLBEntry, aDetails );
+ Sequence< sal_Int8 > aSerNumSeq = xCert->getSerialNumber();
+ const sal_Int8* pSerNumSeq = aSerNumSeq.getConstArray();
+ int nCnt = aSerNumSeq.getLength();
+ String aSerNumStr;
+ const char pHexDigs[ 17 ] = "0123456789ABCEDF";
+ char pBuffer[ 4 ] = " ";
+ UINT8 nNum;
+ for( int i = 0 ; i < nCnt ; ++i )
+ {
+ nNum = UINT8( pSerNumSeq[ i ] );
+ pBuffer[ 0 ] = pHexDigs[ nNum & 0x0F ];
+ nNum >>= 4;
+ pBuffer[ 1 ] = pHexDigs[ nNum ];
+// aSerNumStr += String::CreateFromInt32( UINT8( pSerNumSeq[ i ] ), 16 );
+// aSerNumStr.AppendAscii( " " );
+ aSerNumStr.AppendAscii( pBuffer );
+ }
+ InsertElement( String( ResId( STR_SERIALNUM ) ), aSerNumStr, aSerNumStr );
+ InsertElement( String( ResId( STR_SIGALGORITHM ) ), String::CreateFromAscii( "n/a" ), String() );
+ aLBEntry = XmlSec::GetPureContent( xCert->getIssuerName(), ", " );
+ aDetails = XmlSec::GetPureContent( xCert->getIssuerName(), "\n", true );
+ InsertElement( String( ResId( STR_ISSUER ) ), aLBEntry, aDetails );
+ aLBEntry = aDetails = XmlSec::GetDateTimeString( xCert->getNotBefore() );
+ InsertElement( String( ResId( STR_VALIDFROM ) ), aLBEntry, aDetails );
+ aLBEntry = aDetails = XmlSec::GetDateTimeString( xCert->getNotAfter() );
+ InsertElement( String( ResId( STR_VALIDTO ) ), aLBEntry, aDetails );
+ aLBEntry = XmlSec::GetPureContent( xCert->getSubjectName(), ", " );
+ aDetails = XmlSec::GetPureContent( xCert->getSubjectName(), "\n", true );
+ InsertElement( String( ResId( STR_SUBJECT ) ), aLBEntry, aDetails );
+
+ FreeResource();
+
+ maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) );
+}
+
+CertificateViewerDetailsTP::~CertificateViewerDetailsTP()
+{
+ Clear();
+}
+
+void CertificateViewerDetailsTP::ActivatePage()
+{
+}
+
+IMPL_LINK( CertificateViewerDetailsTP, ElementSelectHdl, void*, EMPTYARG )
+{
+ SvLBoxEntry* pEntry = maElementsLB.FirstSelected();
+ String aElementText;
+ if( pEntry )
+ {
+ aElementText = *( ( String* ) pEntry->GetUserData() );
+ }
+
+ maElementML.SetText( aElementText );
+
+ return 0;
+}
+
+
+
+CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg )
+ :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_CERTPATH ), _pDlg )
+ ,maCertPathFT ( this, ResId( FT_CERTPATH ) )
+ ,maCertPathLB ( this, ResId( LB_SIGNATURES ) )
+ ,maCertStatusFT ( this, ResId( FT_CERTSTATUS ) )
+ ,maCertStatusML ( this, ResId( ML_CERTSTATUS ) )
+{
+ // fill list box
+ Sequence< Reference< security::XCertificate > >
+ aCertPath = _pDlg->mxSecurityEnvironment->buildCertificatePath( _pDlg->mxCert );
+ const Reference< security::XCertificate >*
+ pCertPath = aCertPath.getConstArray();
+
+ String aCN_Id( String::CreateFromAscii( "CN" ) );
+ int nCnt = aCertPath.getLength();
+ for( int i = 0 ; i < nCnt ; ++i )
+ InsertCert( i, XmlSec::GetContentPart( pCertPath[ i ]->getIssuerName(), aCN_Id ), String::CreateFromInt32( i ) );
+
+ FreeResource();
+
+ maCertPathLB.SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) );
+}
+
+CertificateViewerCertPathTP::~CertificateViewerCertPathTP()
+{
+ Clear();
+}
+
+void CertificateViewerCertPathTP::ActivatePage()
+{
+}
+
+IMPL_LINK( CertificateViewerCertPathTP, CertSelectHdl, void*, EMPTYARG )
+{
+ SvLBoxEntry* pEntry = maCertPathLB.FirstSelected();
+ String aStatus;
+ if( pEntry )
+ aStatus = *( ( String* ) pEntry->GetUserData() );
+
+ maCertStatusML.SetText( aStatus );
+
+ return 0;
+}
+
+void CertificateViewerCertPathTP::Clear( void )
+{
+ maCertStatusML.SetText( String() );
+ ULONG i = 0;
+ SvLBoxEntry* pEntry = maCertPathLB.GetEntry( i );
+ while( pEntry )
+ {
+ delete ( String* ) pEntry->GetUserData();
+ ++i;
+ pEntry = maCertPathLB.GetEntry( i );
+ }
+
+ maCertPathLB.Clear();
+}
+
+void CertificateViewerCertPathTP::InsertCert( int _nLevel, const String& _rName, const String& _rStatus )
+{
+ SvLBoxEntry* pEntry = maCertPathLB.InsertEntry( _rName );
+ pEntry->SetUserData( ( void* ) new String( _rStatus ) );
+}
diff --git a/xmlsecurity/source/dialogs/certificateviewer.src b/xmlsecurity/source/dialogs/certificateviewer.src
new file mode 100644
index 000000000000..3749294bdfc1
--- /dev/null
+++ b/xmlsecurity/source/dialogs/certificateviewer.src
@@ -0,0 +1,334 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificateviewer.src,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "dialogs.hrc"
+
+TabDialog RID_XMLSECDLG_CERTVIEWER
+{
+ // HelpID = HID_XMLSECDLG_CERTVIEWER;
+ Size = MAP_APPFONT( TD_WIDTH, TD_HEIGHT );
+ OutputSize = TRUE;
+ Closeable = TRUE;
+ Moveable = TRUE;
+ SVLook = TRUE;
+
+ Text = "View Certificate";
+ Text [ en-US ] = "View Certificate";
+ TabControl 1
+ {
+ Pos = MAP_APPFONT( TD_SP_INNERBORDER_LEFT, TD_SP_INNERBORDER_TOP );
+ Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT+RIDDER_HEIGHT );
+ SVLook = TRUE ;
+ PageList =
+ {
+ PageItem
+ {
+ Identifier = RID_XMLSECTP_GENERAL;
+ Text = "General";
+ Text [ en-US ] = "General";
+ };
+ PageItem
+ {
+ Identifier = RID_XMLSECTP_DETAILS;
+ Text = "Details";
+ Text [ en-US ] = "Details";
+ };
+ PageItem
+ {
+ Identifier = RID_XMLSECTP_CERTPATH;
+ Text = "Certification Path";
+ Text [ en-US ] = "Certification Path";
+ };
+ };
+ };
+ OKButton BTN_OK
+ {
+ Pos = MAP_APPFONT( CV_COL_A, CV_ROW_A );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ DefButton = TRUE;
+ };
+ HelpButton BTN_HELP
+ {
+ Pos = MAP_APPFONT( CV_COL_C, CV_ROW_A );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+};
+
+TabPage RID_XMLSECTP_GENERAL
+{
+// HelpId = HID_XMLSECTP_GENERAL;
+ Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT );
+ OutputSize = TRUE;
+ Hide = TRUE;
+ SVLook = TRUE;
+ Window WIN_FRAME
+ {
+ SVLook = TRUE;
+ Border = TRUE;
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0 );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, CV_CONT_HEIGHT );
+ };
+ FixedImage IMG_CERT
+ {
+ Pos = MAP_APPFONT( CW_COL_0, CW_ROW_0 );
+ Size = MAP_APPFONT( CW_COL_2-CW_COL_0, CW_ROW_2-CW_ROW_0 );
+// Fixed = Image
+// {
+// ImageBitmap = Bitmap { File = "xmlsec_cert_l.bmp"; };
+// MaskColor = STD_MASKCOLOR;
+// };
+ };
+ FixedText FI_CERTINFO
+ {
+ Pos = MAP_APPFONT( CW_COL_3, CW_ROW_1 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_3, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = " Certificate Information";
+ Text [ en-US ] = " Certificate Information";
+ };
+ FixedLine FL_SEP1
+ {
+ Pos = MAP_APPFONT( CW_COL_0, CW_ROW_3 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_0, RSC_CD_FIXEDLINE_HEIGHT );
+ };
+ FixedText FI_HINTNOTTRUST
+ {
+ Pos = MAP_APPFONT( CW_COL_1, CW_ROW_4 );
+ Size = MAP_APPFONT( CW_COL_5a-CW_COL_1, CW_ROW_4a-CW_ROW_4 );
+ WordBreak = TRUE;
+ Text = "This CA Root certificate is not trusted. To enable trust, install this certificate in the Trusted Root Certification Authorities store";
+ Text [ en-US ] = "This CA Root certificate is not trusted. To enable trust, install this certificate in the Trusted Root Certification Authorities store";
+ };
+ FixedLine FL_SEP2
+ {
+ Pos = MAP_APPFONT( CW_COL_0, CW_ROW_5 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_0, RSC_CD_FIXEDLINE_HEIGHT );
+ };
+ FixedText FI_ISSTOLABEL
+ {
+ Pos = MAP_APPFONT( CW_COL_1, CW_ROW_6 );
+ Size = MAP_APPFONT( CW_COL_4-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Issued to:";
+ Text [ en-US ] = "Issued to:";
+ };
+ FixedText FI_ISSTO
+ {
+ Pos = MAP_APPFONT( CW_COL_4, CW_ROW_6 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_4, RSC_CD_FIXEDTEXT_HEIGHT );
+ };
+ FixedText FI_ISSBYLABEL
+ {
+ Pos = MAP_APPFONT( CW_COL_1, CW_ROW_7 );
+ Size = MAP_APPFONT( CW_COL_4-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Issued by:";
+ Text [ en-US ] = "Issued by:";
+ };
+ FixedText FI_ISSBY
+ {
+ Pos = MAP_APPFONT( CW_COL_4, CW_ROW_7 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_4, RSC_CD_FIXEDTEXT_HEIGHT );
+ };
+ FixedText FI_VALFROMLABEL
+ {
+ Pos = MAP_APPFONT( CW_COL_1, CW_ROW_8 );
+ Size = MAP_APPFONT( CW_COL_4a-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Valid from ";
+ Text [ en-US ] = "Valid from ";
+ };
+ FixedText FI_VALFROM
+ {
+ Pos = MAP_APPFONT( CW_COL_4a, CW_ROW_8 );
+ Size = MAP_APPFONT( CW_COL_4b-CW_COL_4a, RSC_CD_FIXEDTEXT_HEIGHT );
+ };
+ FixedText FI_VALTOLABEL
+ {
+ Pos = MAP_APPFONT( CW_COL_4c, CW_ROW_8 );
+ Size = MAP_APPFONT( CW_COL_4d-CW_COL_4c, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = " to ";
+ Text [ en-US ] = " to ";
+ };
+ FixedText FI_VALTO
+ {
+ Pos = MAP_APPFONT( CW_COL_4e, CW_ROW_8 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_4e, RSC_CD_FIXEDTEXT_HEIGHT );
+ };
+ FixedImage IMG_KEY
+ {
+ Pos = MAP_APPFONT( CW_COL_0, CW_ROW_9 );
+ Size = MAP_APPFONT( CW_COL_2-CW_COL_0, CW_ROW_11-CW_ROW_9 );
+// Fixed = Image
+// {
+// ImageBitmap = Bitmap { File = "xmlsec_key.bmp"; };
+// MaskColor = STD_MASKCOLOR;
+// };
+ };
+ FixedText FI_CORRPRIVKEY
+ {
+ Pos = MAP_APPFONT( CW_COL_1a, CW_ROW_10 );
+ Size = MAP_APPFONT( CW_COL_5-CW_COL_1a, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "You have a private key that corresponds to this certificate.";
+ Text [ en-US ] = "You have a private key that corresponds to this certificate.";
+ };
+};
+
+TabPage RID_XMLSECTP_DETAILS
+{
+// HelpId = HID_XMLSECTP_DETAILS;
+ Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT );
+ OutputSize = TRUE;
+ Hide = TRUE;
+ SVLook = TRUE;
+ Control LB_ELEMENTS
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0 );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_1-CV_ROW_0 );
+ SVLook = TRUE;
+ Border = TRUE;
+ };
+ String STR_HEADERBAR
+ {
+ Text = "Field\tValue";
+ Text [ en-US ] = "Field\tValue";
+ };
+ MultiLineEdit ML_ELEMENT
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_2 );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_3-CV_ROW_2 );
+ ReadOnly = TRUE;
+ Border = TRUE;
+ };
+ String STR_VERSION
+ {
+ Text = "Version";
+ Text [ en-US ] = "Version";
+ };
+ String STR_SERIALNUM
+ {
+ Text = "Serial Number";
+ Text [ en-US ] = "Serial Number";
+ };
+ String STR_SIGALGORITHM
+ {
+ Text = "Signature Algorithm";
+ Text [ en-US ] = "Signature Algorithm";
+ };
+ String STR_ISSUER
+ {
+ Text = "Issuer";
+ Text [ en-US ] = "Issuer";
+ };
+ String STR_VALIDFROM
+ {
+ Text = "Valid From";
+ Text [ en-US ] = "Valid From";
+ };
+ String STR_VALIDTO
+ {
+ Text = "Valid to";
+ Text [ en-US ] = "Valid to";
+ };
+ String STR_SUBJECT
+ {
+ Text = "Subject";
+ Text [ en-US ] = "Subject";
+ };
+ String STR_PUBKEY
+ {
+ Text = "Public Key";
+ Text [ en-US ] = "Public Key";
+ };
+};
+
+TabPage RID_XMLSECTP_CERTPATH
+{
+// HelpId = HID_XMLSECTP_CERTPATH;
+ Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT );
+ OutputSize = TRUE;
+ Hide = TRUE;
+ SVLook = TRUE;
+ FixedText FT_CERTPATH
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0 );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Certification path";
+ Text [ en-US ] = "Certification path";
+ };
+ Control LB_SIGNATURES
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0A );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_1-CV_ROW_0A );
+ SVLook = TRUE;
+ Border = TRUE;
+ };
+ FixedText FT_CERTSTATUS
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_2 );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text = "Certification status";
+ Text [ en-US ] = "Certification status";
+ };
+ MultiLineEdit ML_CERTSTATUS
+ {
+ Pos = MAP_APPFONT( CV_COL_0, CV_ROW_2A );
+ Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_3-CV_ROW_2A );
+ ReadOnly = TRUE;
+ Border = TRUE;
+ };
+};
diff --git a/xmlsecurity/source/dialogs/dialogs.hrc b/xmlsecurity/source/dialogs/dialogs.hrc
new file mode 100644
index 000000000000..eda9da08473a
--- /dev/null
+++ b/xmlsecurity/source/dialogs/dialogs.hrc
@@ -0,0 +1,263 @@
+/*************************************************************************
+ *
+ * $RCSfile: dialogs.hrc,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _DIALOGS_HRC
+#define _DIALOGS_HRC
+
+#include <svtools/controldims.hrc>
+
+
+#define STD_MASKCOLOR Color{Red=0xffff;Green=0x0000;Blue=0xffff;}
+
+// --------- general dialog ids ---------
+
+#define RID_XMLSECDLG_DIGSIG 1000
+#define RID_XMLSECDLG_CERTCHOOSER 1001
+#define RID_XMLSECDLG_CERTVIEWER 1002
+#define RID_XMLSECTP_GENERAL 1003
+#define RID_XMLSECTP_DETAILS 1004
+#define RID_XMLSECTP_CERTPATH 1005
+
+#define FL_BOTTOM_SEP 50
+#define BTN_OK 51
+#define BTN_CANCEL 52
+#define BTN_HELP 53
+#define LB_SIGNATURES 54
+#define BTN_VIEWCERT 55
+#define STR_HEADERBAR 56
+
+// --------- general metrics ---------
+#define DLGS_WIDTH 287
+#define DLGS_HEIGHT 195
+// --------- ... for tab dialogs -----
+#define TP_WIDTH 260
+#define TP_HEIGHT 185
+#define RIDDER_HEIGHT (RSC_CD_PUSHBUTTON_HEIGHT)
+#define TD_SP_INNERBORDER_LEFT 3
+#define TD_SP_INNERBORDER_RIGHT 3
+#define TD_SP_INNERBORDER_TOP 3
+#define TD_SP_INNERBORDER_BOTTOM 3
+#define TD_WIDTH (TP_WIDTH+TD_SP_INNERBORDER_LEFT+TD_SP_INNERBORDER_RIGHT)
+#define TD_HEIGHT (TP_HEIGHT+TD_SP_INNERBORDER_TOP+2*TD_SP_INNERBORDER_BOTTOM+RSC_CD_PUSHBUTTON_HEIGHT+RIDDER_HEIGHT)
+
+#define SEP_FL_SPACE_Y 6
+#define SEP_FL_ADJ_Y(val) (val-3)
+#define DLGS_BOTTOM_BTN_L(dlgh) (dlgh-RSC_SP_DLG_INNERBORDER_BOTTOM)
+#define DLGS_BOTTOM_BTN_Y(dlgh) (DLGS_BOTTOM_BTN_L(dlgh)-RSC_CD_PUSHBUTTON_HEIGHT)
+#define DLGS_BOTTOM_FL_Y(dlgh) (DLGS_BOTTOM_BTN_Y(dlgh)-SEP_FL_SPACE_Y-5)
+#define DLGS_BOTTOM_LAST_CTRL_L(dlgh) (DLGS_BOTTOM_BTN_Y(dlgh)-2*SEP_FL_SPACE_Y-3)
+#define DLGS_BOTTOM_HELP_X(dlgw) (dlgw-RSC_SP_DLG_INNERBORDER_RIGHT-RSC_CD_PUSHBUTTON_WIDTH)
+#define DLGS_BOTTOM_CANCEL_X(dlgw) (DLGS_BOTTOM_HELP_X(dlgw)-RSC_SP_CTRL_X-RSC_CD_PUSHBUTTON_WIDTH)
+#define DLGS_BOTTOM_OK_X(dlgw) (DLGS_BOTTOM_CANCEL_X(dlgw)-RSC_SP_CTRL_X-RSC_CD_PUSHBUTTON_WIDTH)
+
+
+// --------- dialog Digital Signatures ---------
+#define BTN_ADDCERT 2
+#define BTN_REMOVECERT 3
+#define FT_HINT_DOC 4
+#define FT_HINT_BASIC 5
+#define FT_HINT_PACK 6
+
+//#define DS_WIDTH DLGS_WIDTH
+//#define DS_HEIGHT DLGS_HEIGHT
+#define DS_BTNWIDTH_1 70
+#define DS_BTNSPACE_X RSC_SP_CTRL_X
+#define DS_WIDTH (RSC_SP_DLG_INNERBORDER_LEFT+RSC_SP_DLG_INNERBORDER_RIGHT+2*DS_BTNSPACE_X+3*DS_BTNWIDTH_1)
+#define DS_HEIGHT (DLGS_WIDTH*2/3)
+
+#define DS_COL_0 RSC_SP_DLG_INNERBORDER_LEFT
+//#define DS_COL_MID (DS_WIDTH/2)
+//#define DS_COL_3 (DS_COL_MID-(DS_BTNWIDTH_1/2))
+//#define DS_COL_4 (DS_COL_2+DS_BTNWIDTH_1)
+//#define DS_COL_2 (DS_COL_3-DS_BTNSPACE_X)
+//#define DS_COL_1 (DS_COL_2-DS_BTNWIDTH_1)
+#define DS_COL_1 DS_COL_0
+#define DS_COL_2 (DS_COL_1+DS_BTNWIDTH_1)
+#define DS_COL_3 (DS_COL_2+DS_BTNSPACE_X)
+#define DS_COL_4 (DS_COL_3+DS_BTNWIDTH_1)
+#define DS_COL_5 (DS_COL_4+DS_BTNSPACE_X)
+//#define DS_COL_6 (DS_COL_5+DS_BTNWIDTH_1)
+#define DS_COL_7 (DS_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT)
+#define DS_COL_6 DS_COL_7
+
+#define DS_ROW_0 RSC_SP_DLG_INNERBORDER_TOP
+#define DS_ROW_1 (DS_ROW_0+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_X)
+#define DS_ROW_7 DLGS_BOTTOM_BTN_L(DS_HEIGHT)
+#define DS_ROW_6 DLGS_BOTTOM_BTN_Y(DS_HEIGHT)
+#define DS_ROW_5 DLGS_BOTTOM_FL_Y(DS_HEIGHT)
+#define DS_ROW_4 DLGS_BOTTOM_LAST_CTRL_L(DS_HEIGHT)
+#define DS_ROW_3 (DS_ROW_4-RSC_CD_PUSHBUTTON_HEIGHT)
+#define DS_ROW_2 (DS_ROW_3-RSC_SP_CTRL_Y)
+
+#define DS_LB_WIDTH (DS_COL_7-DS_COL_0)
+
+// --------- dialog Ceritficate chooser ---------
+#define FT_HINT_SELECT 1
+
+#define CS_WIDTH DLGS_WIDTH
+#define CS_HEIGHT DLGS_HEIGHT
+#define CS_BTNWIDTH_1 DS_BTNWIDTH_1
+
+#define CS_COL_0 RSC_SP_DLG_INNERBORDER_LEFT
+#define CS_COL_2 (CS_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT)
+#define CS_COL_1 (CS_COL_2-CS_BTNWIDTH_1)
+
+#define CS_ROW_0 RSC_SP_DLG_INNERBORDER_TOP
+#define CS_ROW_1 (CS_ROW_0+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_X)
+#define CS_ROW_4 DLGS_BOTTOM_LAST_CTRL_L(CS_HEIGHT)
+#define CS_ROW_3 (CS_ROW_4-RSC_CD_PUSHBUTTON_HEIGHT)
+#define CS_ROW_2 (CS_ROW_3-RSC_SP_CTRL_Y)
+
+#define CS_LB_WIDTH (CS_COL_2-CS_COL_0)
+
+// --------- tab dialog Certificate viewer ---------
+
+#define CV_COL_0 TD_SP_INNERBORDER_LEFT
+#define CV_COL_1 (TP_WIDTH-RSC_SP_TBPG_INNERBORDER_RIGHT)
+#define CV_ROW_0 RSC_SP_TBPG_INNERBORDER_TOP
+#define CV_ROW_3 (TP_HEIGHT-RSC_SP_TBPG_INNERBORDER_BOTTOM)
+#define CV_CONT_WIDTH (CV_COL_1-CV_COL_0)
+#define CV_CONT_HEIGHT (CV_ROW_3-CV_ROW_0)
+#define CV_ROW_1 (CV_ROW_0+2*CV_CONT_HEIGHT/3)
+#define CV_ROW_2 (CV_ROW_1+RSC_SP_CTRL_GROUP_Y)
+
+#define CV_COL_D (TD_WIDTH-TD_SP_INNERBORDER_RIGHT)
+#define CV_COL_C (CV_COL_D-RSC_CD_PUSHBUTTON_WIDTH)
+#define CV_COL_B (CV_COL_C-RSC_SP_CTRL_X)
+#define CV_COL_A (CV_COL_B-RSC_CD_PUSHBUTTON_WIDTH)
+
+#define CV_ROW_B (TD_HEIGHT-TD_SP_INNERBORDER_BOTTOM)
+#define CV_ROW_A (CV_ROW_B-RSC_CD_PUSHBUTTON_HEIGHT)
+
+// --------- tab page Certificate viewer - General ---------
+#define WIN_FRAME 2
+#define IMG_CERT 3
+#define FI_CERTINFO 4
+#define FL_SEP1 5
+#define FI_HINTNOTTRUST 6
+#define FL_SEP2 7
+#define FI_ISSTOLABEL 8
+#define FI_ISSTO 9
+#define FI_ISSBYLABEL 10
+#define FI_ISSBY 11
+#define FI_VALFROMLABEL 12
+#define FI_VALFROM 13
+#define FI_VALTOLABEL 14
+#define FI_VALTO 15
+#define IMG_KEY 16
+#define FI_CORRPRIVKEY 17
+
+#define IMG1_WIDTH 33
+#define IMG1_HEIGHT 22
+#define IMG2_WIDTH 20
+#define IMG2_HEIGHT 20
+#define DATE_WIDTH 30
+#define CW_COL_0 (CV_COL_0+RSC_SP_GRP_INNERBORDER_LEFT)
+#define CW_COL_1 (CW_COL_0+RSC_SP_FLGR_SPACE_X)
+#define CW_COL_1a (CW_COL_0+IMG2_WIDTH+1)
+#define CW_COL_2 (CW_COL_0+IMG1_WIDTH)
+#define CW_COL_3 (CW_COL_2+RSC_SP_CTRL_GROUP_X)
+#define CW_COL_4 (CW_COL_1+40)
+#define CW_COL_5 (CV_CONT_WIDTH-RSC_SP_GRP_INNERBORDER_RIGHT)
+#define CW_COL_5a (CW_COL_5-RSC_SP_GRP_INNERBORDER_RIGHT)
+#define CW_COL_4a (CW_COL_1+38)
+#define CW_COL_4b (CW_COL_4a+DATE_WIDTH)
+#define CW_COL_4c (CW_COL_4b+3)
+#define CW_COL_4d (CW_COL_4c+8)
+#define CW_COL_4e (CW_COL_4d+3)
+#define CW_ROW_0 (CV_ROW_0+RSC_SP_GRP_INNERBORDER_TOP)
+#define CW_ROW_1 (CW_ROW_0+RSC_SP_GRP_INNERBORDER_TOP)
+#define CW_ROW_2 (CW_ROW_0+IMG1_HEIGHT)
+#define CW_ROW_3 (CW_ROW_2+3)
+#define CW_ROW_4 (CW_ROW_3+RSC_SP_CTRL_Y+RSC_CD_FIXEDLINE_HEIGHT)
+#define CW_ROW_4a (CW_ROW_4+35)
+#define CW_ROW_5 (CW_ROW_4a+3)
+#define CW_ROW_6 (CW_ROW_5+RSC_SP_CTRL_Y+RSC_CD_FIXEDLINE_HEIGHT)
+#define CW_ROW_7 (CW_ROW_6+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT)
+#define CW_ROW_8 (CW_ROW_7+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT)
+#define CW_ROW_9 (CW_ROW_8+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT)
+#define CW_ROW_10 (CW_ROW_9+2)
+#define CW_ROW_11 (CW_ROW_9+IMG2_HEIGHT)
+
+// --------- tab page Certificate viewer - Details ---------
+
+#define LB_ELEMENTS 1
+#define ML_ELEMENT 2
+
+#define STR_VERSION 1
+#define STR_SERIALNUM 2
+#define STR_SIGALGORITHM 3
+#define STR_ISSUER 4
+#define STR_VALIDFROM 5
+#define STR_VALIDTO 6
+#define STR_SUBJECT 7
+#define STR_PUBKEY 8
+
+// --------- tab page Certificate viewer - Certification Path ---------
+
+#define FT_CERTPATH 1
+#define FT_CERTSTATUS 2
+#define ML_CERTSTATUS 3
+
+#define CV_ROW_0A (CV_ROW_0+RSC_SP_CTRL_DESC_Y+RSC_CD_FIXEDTEXT_HEIGHT)
+#define CV_ROW_2A (CV_ROW_2+RSC_SP_CTRL_DESC_Y+RSC_CD_FIXEDTEXT_HEIGHT)
+
+#endif
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
new file mode 100644
index 000000000000..65650a5645ea
--- /dev/null
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -0,0 +1,545 @@
+/*************************************************************************
+ *
+ * $RCSfile: digitalsignaturesdialog.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 <xmlsecurity/digitalsignaturesdialog.hxx>
+#include <xmlsecurity/certificatechooser.hxx>
+#include <xmlsecurity/certificateviewer.hxx>
+
+#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
+#include <com/sun/star/embed/XStorage.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
+#include <com/sun/star/embed/ElementModes.hpp>
+#endif
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+
+// Only needed until sig is in storage:
+#include <unotools/streamhelper.hxx>
+
+/*-
+ * deleted by AF. base64.h is a mozilla nss file, this file should not depend
+ * on nss/nspr.
+ */
+//#include <external/base64.h>
+
+#if OSL_DEBUG_LEVEL > 1
+#include <vcl/msgbox.hxx>
+#endif
+
+#include <tools/intn.hxx>
+
+#include "dialogs.hrc"
+#include "resourcemanager.hxx"
+
+// MM : added for password exception
+#include <com/sun/star/security/NoPasswordException.hpp>
+using namespace ::com::sun::star::security;
+
+/* HACK: disable some warnings for MS-C */
+#ifdef _MSC_VER
+#pragma warning (disable : 4355) // 4355: this used in initializer-list
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star;
+
+DigitalSignaturesDialog::DigitalSignaturesDialog( Window* pParent, uno::Reference< lang::XMultiServiceFactory >& rxMSF, DocumentSignatureMode eMode )
+ :ModalDialog ( pParent, XMLSEC_RES( RID_XMLSECDLG_DIGSIG ) )
+ ,maSignatureHelper ( rxMSF )
+ ,meSignatureMode ( eMode )
+ ,maHintDocFT ( this, ResId( FT_HINT_DOC ) )
+ ,maHintBasicFT ( this, ResId( FT_HINT_BASIC ) )
+ ,maHintPackageFT ( this, ResId( FT_HINT_PACK ) )
+ ,maSignaturesLB ( this, ResId( LB_SIGNATURES ) )
+ ,maViewBtn ( this, ResId( BTN_VIEWCERT ) )
+ ,maAddBtn ( this, ResId( BTN_ADDCERT ) )
+ ,maRemoveBtn ( this, ResId( BTN_REMOVECERT ) )
+ ,maBottomSepFL ( this, ResId( FL_BOTTOM_SEP ) )
+ ,maOKBtn ( this, ResId( BTN_OK ) )
+ ,maCancelBtn ( this, ResId( BTN_CANCEL ) )
+ ,maHelpBtn ( this, ResId( BTN_HELP ) )
+{
+ static long nTabs[] = { 3, 0, 32*DS_LB_WIDTH/100, 64*DS_LB_WIDTH/100 };
+ maSignaturesLB.SetTabs( &nTabs[ 0 ] );
+ maSignaturesLB.InsertHeaderEntry( String( ResId( STR_HEADERBAR ) ) );
+
+ FreeResource();
+ mbVerifySignatures = true;
+
+ maSignaturesLB.SetSelectHdl( LINK( this, DigitalSignaturesDialog, SignatureHighlightHdl ) );
+ maSignaturesLB.SetDoubleClickHdl( LINK( this, DigitalSignaturesDialog, SignatureSelectHdl ) );
+
+ maViewBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, ViewButtonHdl ) );
+ maViewBtn.Disable();
+
+ maAddBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, AddButtonHdl ) );
+
+ maRemoveBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, RemoveButtonHdl ) );
+ maRemoveBtn.Disable();
+
+ switch( meSignatureMode )
+ {
+ case SignatureModeDocumentContent: maHintDocFT.Show(); break;
+ case SignatureModeMacros: maHintBasicFT.Show(); break;
+ case SignatureModePackage: maHintPackageFT.Show(); break;
+ }
+}
+
+DigitalSignaturesDialog::~DigitalSignaturesDialog()
+{
+}
+
+BOOL DigitalSignaturesDialog::Init( const rtl::OUString& rTokenName )
+{
+ bool bInit = maSignatureHelper.Init( rTokenName );
+
+ DBG_ASSERT( bInit, "Error initializing security context!" );
+
+ if ( bInit )
+ {
+ maSignatureHelper.SetStartVerifySignatureHdl( LINK( this, DigitalSignaturesDialog, StartVerifySignatureHdl ) );
+ }
+
+ return bInit;
+}
+
+void DigitalSignaturesDialog::SetStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStore )
+{
+ mxStore = rxStore;
+ maSignatureHelper.SetStorage( mxStore );
+}
+
+
+
+short DigitalSignaturesDialog::Execute()
+{
+ // Verify Signatures and add certificates to ListBox...
+ mbVerifySignatures = true;
+ ImplGetSignatureInformations();
+ ImplFillSignaturesBox();
+
+ // Only verify once, content will not change.
+ // But for refreshing signature information, StartVerifySignatureHdl will be called after each add/remove
+ mbVerifySignatures = false;
+
+ short nRet = Dialog::Execute();
+
+ return nRet;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, SignatureHighlightHdl, void*, EMPTYARG )
+{
+ bool bSel = maSignaturesLB.FirstSelected() != 0;
+ maViewBtn.Enable( bSel );
+ maRemoveBtn.Enable( bSel );
+ return 0;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, SignatureSelectHdl, void*, EMPTYARG )
+{
+ ImplShowSignaturesDetails();
+ return 0;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, ViewButtonHdl, Button*, EMPTYARG )
+{
+ ImplShowSignaturesDetails();
+ return 0;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG )
+{
+ try
+ {
+ // Check if we have the password for the key store.
+ // If no, we don't want to raise an empty dialog.
+ maSignatureHelper.GetSecurityEnvironment()->getPersonalCertificates();
+
+ uno::Reference<com::sun::star::xml::crypto::XSecurityEnvironment> xSecEnv = maSignatureHelper.GetSecurityEnvironment();
+ CertificateChooser aChooser( (Window*)this, xSecEnv, aCurrentSignatureInformations );
+ if( aChooser.Execute() )
+ {
+ maSignatureHelper.StartMission();
+
+ sal_Int32 nSecurityId = maSignatureHelper.GetNewSecurityId();
+ uno::Reference< ::com::sun::star::security::XCertificate > xCert = aChooser.GetSelectedCertificate();
+ maSignatureHelper.SetX509Certificate( nSecurityId, xCert->getIssuerName(), bigIntegerToNumericString( xCert->getSerialNumber() ) );
+
+ std::vector< rtl::OUString > aElements = CreateElementList( mxStore, rtl::OUString(), meSignatureMode );
+
+ ::rtl::OUString aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) );
+ sal_Int32 nElements = aElements.size();
+ for ( sal_Int32 n = 0; n < nElements; n++ )
+ {
+ bool bBinaryMode = true;
+ sal_Int32 nSep = aElements[n].lastIndexOf( '.' );
+ if ( nSep != (-1) )
+ {
+ ::rtl::OUString aExt = aElements[n].copy( nSep+1 );
+ if ( aExt.equalsIgnoreAsciiCase( aXMLExt ) )
+ bBinaryMode = false;
+ }
+ maSignatureHelper.AddForSigning( nSecurityId, aElements[n], aElements[n], bBinaryMode );
+ }
+
+ bool bDone = false;
+ bool bRefreshInformations = false;
+
+ if ( !maSigFileName.getLength() )
+ {
+ ::rtl::OUString aSIGStreamName( RTL_CONSTASCII_USTRINGPARAM( "SIGNATURES" ) );
+ uno::Reference < io::XStream > xStream = mxStore->openStreamElement( aSIGStreamName, embed::ElementModes::WRITE );
+ uno::Reference< io::XOutputStream > xOutputStream( xStream, uno::UNO_QUERY );
+ // CHANGE TO KEEP OLD SIGS WHEN SIG IN STREAM WORKS!
+ //bDone = maSignatureHelper.CreateAndWriteSignatue( xOutputStream );
+
+ uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream);
+ // Export old signatures...
+ int nInfos = aCurrentSignatureInformations.size();
+ for ( int n = 0; n < nInfos; n++ )
+ maSignatureHelper.ExportSignature( xDocumentHandler, aCurrentSignatureInformations[n]);
+
+ // Create a new one...
+ bDone = maSignatureHelper.CreateAndWriteSignatue( xDocumentHandler );
+
+ // That's it...
+ maSignatureHelper.CloseDocumentHandler( xDocumentHandler);
+
+ uno::Reference< embed::XTransactedObject > xTrans( mxStore, uno::UNO_QUERY );
+ xTrans->commit();
+ uno::Reference< lang::XComponent > xComp( mxStore, uno::UNO_QUERY );
+ xComp->dispose();
+ }
+ else
+ {
+ SvFileStream* pStream = new SvFileStream( maSigFileName, STREAM_WRITE|STREAM_TRUNC );
+ SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
+ uno::Reference< io::XOutputStream > xOutputStream = new utl::OOutputStreamHelper( xLockBytes );
+
+ uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream);
+ // Export old signatures...
+ int nInfos = aCurrentSignatureInformations.size();
+ for ( int n = 0; n < nInfos; n++ )
+ maSignatureHelper.ExportSignature( xDocumentHandler, aCurrentSignatureInformations[n]);
+
+ // Create a new one...
+ bDone = maSignatureHelper.CreateAndWriteSignatue( xDocumentHandler );
+
+ // That's it...
+ maSignatureHelper.CloseDocumentHandler( xDocumentHandler);
+ }
+
+ maSignatureHelper.EndMission();
+
+ if ( bDone )
+ {
+ // Can't simply remember current information, need parsing for getting full information :(
+ ImplGetSignatureInformations();
+ ImplFillSignaturesBox();
+ }
+
+ }
+ }
+ catch (NoPasswordException&)
+ {
+ }
+
+ return 0;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG )
+{
+ if( maSignaturesLB.FirstSelected() )
+ {
+ USHORT nSelected = (USHORT) maSignaturesLB.FirstSelected()->GetUserData();
+ aCurrentSignatureInformations.erase( aCurrentSignatureInformations.begin()+nSelected );
+
+ // Export all other signatures...
+ if ( !maSigFileName.getLength() )
+ {
+ // See AddButtonHdl, later....
+ }
+ else
+ {
+ SvFileStream* pStream = new SvFileStream( maSigFileName, STREAM_WRITE|STREAM_TRUNC );
+ SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
+ uno::Reference< io::XOutputStream > xOutputStream = new utl::OOutputStreamHelper( xLockBytes );
+
+ uno::Reference< css::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream);
+
+ int nInfos = aCurrentSignatureInformations.size();
+ for( int n = 0 ; n < nInfos ; ++n )
+ maSignatureHelper.ExportSignature( xDocumentHandler, aCurrentSignatureInformations[ n ] );
+
+ // That's it...
+ maSignatureHelper.CloseDocumentHandler( xDocumentHandler );
+ }
+
+ ImplFillSignaturesBox();
+ }
+
+ return 0;
+}
+
+IMPL_LINK( DigitalSignaturesDialog, StartVerifySignatureHdl, void*, EMPTYARG )
+{
+ return mbVerifySignatures ? 1 : 0;
+}
+
+void DigitalSignaturesDialog::ImplFillSignaturesBox()
+{
+ maSignaturesLB.Clear();
+
+ uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecEnv = maSignatureHelper.GetSecurityEnvironment();
+ uno::Reference< ::com::sun::star::security::XCertificate > xCert;
+
+ String aCN_Id( String::CreateFromAscii( "CN" ) );
+ int nInfos = aCurrentSignatureInformations.size();
+ for( int n = 0; n < nInfos; ++n )
+ {
+ const SignatureInformation& rInfo = aCurrentSignatureInformations[n];
+ xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
+
+ // If we don't get it, create it from signature data:
+ if ( !xCert.is() )
+ xCert = xSecEnv->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
+
+ DBG_ASSERT( xCert.is(), "Certificate not found and can't be created!" );
+
+ String aSubject;
+ String aIssuer;
+ String aDateTimeStr;
+ if( xCert.is() )
+ {
+ aSubject = XmlSec::GetContentPart( xCert->getSubjectName(), aCN_Id );
+ aIssuer = XmlSec::GetContentPart( rInfo.ouX509IssuerName, aCN_Id );
+ aDateTimeStr = XmlSec::GetDateString( xCert->getNotAfter() );
+ }
+ else
+ {
+#if OSL_DEBUG_LEVEL > 1
+ aSubject = String::CreateFromAscii( "ERROR getting certificate!" );
+#endif
+ }
+ SvLBoxEntry* pEntry = maSignaturesLB.InsertEntry( aSubject );
+ maSignaturesLB.SetEntryText( aIssuer, pEntry, 1 );
+ maSignaturesLB.SetEntryText( aDateTimeStr, pEntry, 2 );
+ pEntry->SetUserData( ( void* ) n ); // missuse user data as index
+ }
+
+// maViewBtn.Disable();
+ SignatureHighlightHdl( NULL );
+}
+
+void DigitalSignaturesDialog::ImplGetSignatureInformations()
+{
+ aCurrentSignatureInformations.clear();
+
+ maSignatureHelper.StartMission();
+
+ bool bVerifyOK = false;
+
+ if ( maSigFileName.getLength() )
+ {
+ SvFileStream* pStream = new SvFileStream( maSigFileName, STREAM_READ );
+ pStream->Seek( STREAM_SEEK_TO_END );
+ ULONG nBytes = pStream->Tell();
+ pStream->Seek( STREAM_SEEK_TO_BEGIN );
+ SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
+ if ( nBytes )
+ {
+ uno::Reference< io::XInputStream > xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
+ bVerifyOK = maSignatureHelper.ReadAndVerifySignatue( xInputStream );
+ xInputStream->closeInput();
+ }
+ }
+ else
+ {
+ ::rtl::OUString aSIGStreamName( RTL_CONSTASCII_USTRINGPARAM( "SIGNATURE" ) );
+ if ( mxStore->isStreamElement( aSIGStreamName ) )
+ {
+ uno::Reference < io::XStream > xStream = mxStore->openStreamElement( aSIGStreamName, embed::ElementModes::READ );
+ uno::Reference< io::XInputStream > xInputStream( xStream, uno::UNO_QUERY );
+ bVerifyOK = maSignatureHelper.ReadAndVerifySignatue( xInputStream );
+ }
+ }
+
+ if ( bVerifyOK )
+ aCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations();
+
+ maSignatureHelper.EndMission();
+
+ mbVerifySignatures = false;
+}
+
+void DigitalSignaturesDialog::ImplShowSignaturesDetails()
+{
+ if( maSignaturesLB.FirstSelected() )
+ {
+ USHORT nSelected = (USHORT) maSignaturesLB.FirstSelected()->GetUserData();
+ const SignatureInformation& rInfo = aCurrentSignatureInformations[ nSelected ];
+ uno::Reference< dcss::security::XCertificate > xCert = maSignatureHelper.GetSecurityEnvironment()->getCertificate( rInfo.ouX509IssuerName, numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
+
+ // If we don't get it, create it from signature data:
+ if ( !xCert.is() )
+ xCert = maSignatureHelper.GetSecurityEnvironment()->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
+
+ DBG_ASSERT( xCert.is(), "Certificate not found and can't be created!" );
+
+ uno::Reference<com::sun::star::xml::crypto::XSecurityEnvironment> xSecEnv = maSignatureHelper.GetSecurityEnvironment();
+ CertificateViewer aViewer( this, xSecEnv, xCert );
+ aViewer.Execute();
+ }
+}
+
+void ImplFillElementList( std::vector< rtl::OUString >& rList, uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, bool bRecursive )
+{
+ ::rtl::OUString aMetaInfName( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) );
+ ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
+
+ uno::Reference < container::XNameAccess > xElements( rxStore, uno::UNO_QUERY );
+ uno::Sequence< ::rtl::OUString > aElements = xElements->getElementNames();
+ sal_Int32 nElements = aElements.getLength();
+ const ::rtl::OUString* pNames = aElements.getConstArray();
+ for ( sal_Int32 n = 0; n < nElements; n++ )
+ {
+ if ( pNames[n] != aMetaInfName )
+ {
+ if ( rxStore->isStreamElement( pNames[n] ) )
+ {
+ ::rtl::OUString aFullName( rRootStorageName + pNames[n] );
+ rList.push_back( aFullName );
+ }
+ else if ( bRecursive && rxStore->isStorageElement( pNames[n] ) )
+ {
+ uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( pNames[n], embed::ElementModes::READ );
+ rtl::OUString aFullRootName( rRootStorageName + pNames[n] + aSep );
+ ImplFillElementList( rList, rxStore, aFullRootName, bRecursive );
+ }
+ }
+ }
+}
+
+std::vector< rtl::OUString > DigitalSignaturesDialog::CreateElementList( uno::Reference < embed::XStorage >& rxStore, const ::rtl::OUString rRootStorageName, DocumentSignatureMode eMode )
+{
+ std::vector< rtl::OUString > aElements;
+ ::rtl::OUString aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
+
+
+ switch ( eMode )
+ {
+ case SignatureModeDocumentContent:
+ {
+ // 1) Main content
+ ImplFillElementList( aElements, rxStore, ::rtl::OUString(), false );
+
+ // 2) Pictures...
+ rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Pictures" ) );
+ try
+ {
+ uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ );
+ ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true );
+ }
+ catch( com::sun::star::io::IOException& )
+ {
+ ; // Doesn't have to exist...
+ }
+ }
+ break;
+ case SignatureModeMacros:
+ {
+ // 1) Macros
+ rtl::OUString aSubStorageName( rtl::OUString::createFromAscii( "Basic" ) );
+ try
+ {
+ uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ );
+ ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true );
+ }
+ catch( com::sun::star::io::IOException& )
+ {
+ ; // Doesn't have to exist...
+ }
+
+ // 2) Dialogs
+ aSubStorageName = rtl::OUString::createFromAscii( "Dialogs") ;
+ try
+ {
+ uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aSubStorageName, embed::ElementModes::READ );
+ ImplFillElementList( aElements, xSubStore, aSubStorageName+aSep, true );
+ }
+ catch( com::sun::star::io::IOException& )
+ {
+ ; // Doesn't have to exist...
+ }
+ }
+ break;
+ case SignatureModePackage:
+ {
+ // Everything except META-INF
+ ImplFillElementList( aElements, rxStore, ::rtl::OUString(), true );
+ }
+ break;
+ }
+
+ return aElements;
+}
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.src b/xmlsecurity/source/dialogs/digitalsignaturesdialog.src
new file mode 100644
index 000000000000..8ea04dc9e2fd
--- /dev/null
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.src
@@ -0,0 +1,159 @@
+/*************************************************************************
+ *
+ * $RCSfile: digitalsignaturesdialog.src,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 "dialogs.hrc"
+
+ModalDialog RID_XMLSECDLG_DIGSIG
+{
+// HelpId = HID_XMLSECDLG_DIGSIG;
+ Size = MAP_APPFONT( DS_WIDTH, DS_HEIGHT );
+ OutputSize = TRUE;
+ Closeable = TRUE;
+ Moveable = TRUE;
+ SVLook = TRUE;
+
+// Text = "Digital Signatures";
+ Text = "Digital Signatures";
+ Text [ en-US ] = "Digital Signatures";
+
+ FixedText FT_HINT_DOC
+ {
+ Pos = MAP_APPFONT( DS_COL_0, DS_ROW_0 );
+ Size = MAP_APPFONT( DS_COL_7-DS_COL_0, RSC_CD_FIXEDTEXT_HEIGHT );
+ Hide = TRUE;
+ Text = "The following have signed the document content";
+ Text [ en-US ] = "The following have signed the document content";
+ };
+ FixedText FT_HINT_BASIC
+ {
+ Pos = MAP_APPFONT( DS_COL_0, DS_ROW_0 );
+ Size = MAP_APPFONT( DS_COL_7-DS_COL_0, RSC_CD_FIXEDTEXT_HEIGHT );
+ Hide = TRUE;
+ Text = "The following have signed the document macro";
+ Text [ en-US ] = "The following have signed the document macro";
+ };
+ FixedText FT_HINT_PACK
+ {
+ Pos = MAP_APPFONT( DS_COL_0, DS_ROW_0 );
+ Size = MAP_APPFONT( DS_COL_7-DS_COL_0, RSC_CD_FIXEDTEXT_HEIGHT );
+ Hide = TRUE;
+ Text = "The following have signed this package";
+ Text [ en-US ] = "The following have signed this package";
+ };
+// ListBox LB_SIGNATURES
+ Control LB_SIGNATURES
+ {
+ Pos = MAP_APPFONT( DS_COL_0, DS_ROW_1 );
+ Size = MAP_APPFONT( DS_LB_WIDTH, DS_ROW_2-DS_ROW_1 );
+ SVLook = TRUE;
+ Border = TRUE;
+ };
+ String STR_HEADERBAR
+ {
+ Text = "Signer\tDigital ID Issued by\tDate";
+ Text [ en-US ] = "Signer\tDigital ID Issued by\tDate";
+ };
+ PushButton BTN_VIEWCERT
+ {
+ Pos = MAP_APPFONT( DS_COL_1, DS_ROW_3 );
+ Size = MAP_APPFONT( DS_COL_2-DS_COL_1, RSC_CD_PUSHBUTTON_HEIGHT );
+// Text = "Zertifikat anzeigen...";
+ Text = "View Certificate...";
+ Text [ en-US ] = "View Certificate...";
+ };
+ PushButton BTN_ADDCERT
+ {
+ Pos = MAP_APPFONT( DS_COL_3, DS_ROW_3 );
+ Size = MAP_APPFONT( DS_COL_4-DS_COL_3, RSC_CD_PUSHBUTTON_HEIGHT );
+// Text = "Hinzufgen...";
+ Text = "Add...";
+ Text [ en-US ] = "Add...";
+ };
+ PushButton BTN_REMOVECERT
+ {
+ Pos = MAP_APPFONT( DS_COL_5, DS_ROW_3 );
+ Size = MAP_APPFONT( DS_COL_6-DS_COL_5, RSC_CD_PUSHBUTTON_HEIGHT );
+// Text = "Entfernen";
+ Text = "Remove";
+ Text [ en-US ] = "Remove";
+ };
+ FixedLine FL_BOTTOM_SEP
+ {
+ Pos = MAP_APPFONT( 0, DLGS_BOTTOM_FL_Y( DS_HEIGHT ) );
+ Size = MAP_APPFONT( DS_WIDTH, RSC_CD_FIXEDLINE_HEIGHT );
+ };
+ OKButton BTN_OK
+ {
+ DefButton = TRUE;
+ Pos = MAP_APPFONT( DLGS_BOTTOM_OK_X( DS_WIDTH ), DLGS_BOTTOM_BTN_Y( DS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+ CancelButton BTN_CANCEL
+ {
+ Pos = MAP_APPFONT( DLGS_BOTTOM_CANCEL_X( DS_WIDTH ), DLGS_BOTTOM_BTN_Y( DS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+ HelpButton BTN_HELP
+ {
+ Pos = MAP_APPFONT( DLGS_BOTTOM_HELP_X( DS_WIDTH ), DLGS_BOTTOM_BTN_Y( DS_HEIGHT ) );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+};
diff --git a/xmlsecurity/source/dialogs/makefile.mk b/xmlsecurity/source/dialogs/makefile.mk
new file mode 100644
index 000000000000..bf12824c8e0a
--- /dev/null
+++ b/xmlsecurity/source/dialogs/makefile.mk
@@ -0,0 +1,100 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+#
+# 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=dialogs
+TARGETTYPE=GUI
+
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+
+# --- Files --------------------------------------------------------
+
+BMP_IN=$(PRJ)$/res
+
+SRS1NAME=dialogs
+SRC1FILES = \
+ digitalsignaturesdialog.src \
+ certificatechooser.src \
+ certificateviewer.src
+
+SLOFILES= \
+ $(SLO)$/stbcontrl.obj \
+ $(SLO)$/digitalsignaturesdialog.obj \
+ $(SLO)$/certificatechooser.obj \
+ $(SLO)$/certificateviewer.obj \
+ $(SLO)$/resourcemanager.obj
+
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/dialogs/resourcemanager.cxx b/xmlsecurity/source/dialogs/resourcemanager.cxx
new file mode 100644
index 000000000000..aa19d487bc3b
--- /dev/null
+++ b/xmlsecurity/source/dialogs/resourcemanager.cxx
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * $RCSfile: resourcemanager.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 "resourcemanager.hxx"
+
+#include <vcl/svapp.hxx>
+#include <svtools/solar.hrc>
+
+
+namespace XmlSec
+{
+ static ResMgr* pResMgr = 0;
+ static International* pInternational = 0;
+
+ ResMgr* GetResMgr( void )
+ {
+ if( !pResMgr )
+ {
+ ByteString aName( "xmlsec" );
+ aName += ByteString::CreateFromInt32( SOLARUPD );
+// pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), Application::GetSettings().GetUILanguage() );
+ LanguageType aLang( LANGUAGE_ENGLISH_US );
+// pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), aLang );
+// MT: Change to Locale
+ pResMgr = ResMgr::CreateResMgr( aName.GetBuffer());
+ }
+
+ return pResMgr;
+ }
+
+ International* GetInternational( void )
+ {
+ if( !pInternational )
+ {
+ LanguageType aLang( LANGUAGE_ENGLISH_US );
+ pInternational = new International( aLang );
+ }
+ return pInternational;
+ }
+
+ DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT )
+ {
+ return DateTime(
+ Date( _rDT.Day, _rDT.Month, _rDT.Year ),
+ Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) );
+ }
+
+ String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT )
+ {
+ return GetInternational()->GetLongDate( GetDateTime( _rDT ) );
+ }
+
+ String GetDateString( const ::com::sun::star::util::DateTime& _rDT )
+ {
+ return GetInternational()->GetLongDate( GetDateTime( _rDT ) );
+ }
+
+ String GetPureContent( const String& _rRawString, const char* _pCommaReplacement, bool _bPreserveId )
+ {
+ enum STATE { ID, EQUALSIGN, CONT };
+ String s;
+ STATE e = ID;
+
+ const sal_Unicode* p = _rRawString.GetBuffer();
+ sal_Unicode c;
+ const sal_Unicode cComma = ',';
+ const sal_Unicode cEqualSign = '=';
+ String aCommaReplacement;
+ if( _pCommaReplacement )
+ aCommaReplacement = String::CreateFromAscii( _pCommaReplacement );
+
+ while( *p )
+ {
+ c = *p;
+ switch( e )
+ {
+ case ID:
+ if( _bPreserveId )
+ s += c;
+
+ if( c == cEqualSign )
+ e = CONT;
+ break;
+// case EQUALSIGN:
+// break;
+ case CONT:
+ if( c == cComma )
+ {
+ s += aCommaReplacement;
+ e = ID;
+ }
+ else
+ s += c;
+ break;
+ }
+
+ ++p;
+ }
+
+// xub_StrLen nEquPos = _rRawString.SearchAscii( "=" );
+// if( nEquPos == STRING_NOTFOUND )
+// s = _rRawString;
+// else
+// {
+// ++nEquPos;
+// s = String( _rRawString, nEquPos, STRING_MAXLEN );
+// s.EraseLeadingAndTrailingChars();
+// }
+
+ return s;
+ }
+
+ String GetContentPart( const String& _rRawString, const String& _rPartId )
+ {
+ String s;
+
+ xub_StrLen nContStart = _rRawString.Search( _rPartId );
+ if( nContStart != STRING_NOTFOUND )
+ {
+ nContStart += _rPartId.Len();
+ ++nContStart; // now it's start of content, directly after Id
+
+ xub_StrLen nContEnd = _rRawString.Search( sal_Unicode( ',' ), nContStart );
+
+ s = String( _rRawString, nContStart, nContEnd - nContStart );
+ }
+
+ return s;
+ }
+}
+
+
diff --git a/xmlsecurity/source/dialogs/resourcemanager.hxx b/xmlsecurity/source/dialogs/resourcemanager.hxx
new file mode 100644
index 000000000000..3b215dfbe7bb
--- /dev/null
+++ b/xmlsecurity/source/dialogs/resourcemanager.hxx
@@ -0,0 +1,96 @@
+/*************************************************************************
+ *
+ * $RCSfile: resourcemanager.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 _RESOURCEMANAGER_HXX
+#define _RESOURCEMANAGER_HXX
+
+#ifndef _TOOLS_RESMGR_HXX
+#include <tools/resmgr.hxx>
+#endif
+#ifndef _TOOLS_INTN_HXX
+#include <tools/intn.hxx>
+#endif
+#ifndef _DATETIME_HXX
+#include <tools/datetime.hxx>
+#endif
+#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
+#include <com/sun/star/util/DateTime.hpp>
+#endif
+
+
+namespace XmlSec
+{
+ ResMgr* GetResMgr( void );
+
+ International* GetInternational( void );
+ DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT );
+ String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT );
+ String GetDateString( const ::com::sun::star::util::DateTime& _rDT );
+
+ String GetPureContent( const String& _rRawString,
+ const char* _pCommaReplacement = ", ",
+ bool _bPreserveId = false ); // strips "CN=" and so from string
+ String GetContentPart( const String& _rRawString, const String& _rPartId );
+}
+
+#define XMLSEC_RES(id) ResId(id,XmlSec::GetResMgr())
+
+#endif
diff --git a/xmlsecurity/source/dialogs/stbcontrl.cxx b/xmlsecurity/source/dialogs/stbcontrl.cxx
new file mode 100644
index 000000000000..a4d92885b424
--- /dev/null
+++ b/xmlsecurity/source/dialogs/stbcontrl.cxx
@@ -0,0 +1,232 @@
+/*************************************************************************
+ *
+ * $RCSfile: stbcontrl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:24 $
+ *
+ * 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 WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRUNTIES 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 ---------------------------------------------------------------
+
+#ifndef _SHL_HXX //autogen
+#include <tools/shl.hxx>
+#endif
+#ifndef _STATUS_HXX //autogen
+#include <vcl/status.hxx>
+#endif
+#ifndef _MENU_HXX //autogen
+#include <vcl/menu.hxx>
+#endif
+#ifndef _SV_IMAGE_HXX
+#include <vcl/image.hxx>
+#endif
+//#ifndef _SFXITEMPOOL_HXX
+//#include <svtools/itempool.hxx>
+//#endif
+#ifndef _SFXAPP_HXX
+#include <sfx2/app.hxx>
+#endif
+#ifndef _SFXMODULE_HXX
+#include <sfx2/module.hxx>
+#endif
+#ifndef _SFXDISPATCH_HXX //autogen
+#include <sfx2/dispatch.hxx>
+#endif
+#ifndef _SFX_OBJSH_HXX //autogen
+#include <sfx2/objsh.hxx>
+#endif
+
+#include <svtools/eitem.hxx>
+
+
+#include <xmlsecurity/stbcontrl.hxx>
+
+#define PAINT_OFFSET 5
+
+//#include "sizeitem.hxx"
+//#include "dialmgr.hxx"
+//#include "dlgutil.hxx"
+//#include "stbctrls.h"
+
+//#include "dialogs.hrc"
+
+/*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
+#include <unotools/localedatawrapper.hxx>
+#endif
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif*/
+
+
+
+SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxBoolItem );
+
+/*
+class FunctionPopup_Impl : public PopupMenu
+{
+public:
+ FunctionPopup_Impl( USHORT nCheck );
+
+ USHORT GetSelected() const { return nSelected; }
+
+private:
+ USHORT nSelected;
+
+ virtual void Select();
+};
+
+// -----------------------------------------------------------------------
+
+FunctionPopup_Impl::FunctionPopup_Impl( USHORT nCheck ) :
+ PopupMenu( ResId( RID_SVXMNU_PSZ_FUNC, DIALOG_MGR() ) ),
+ nSelected( 0 )
+{
+ if (nCheck)
+ CheckItem( nCheck );
+}
+
+// -----------------------------------------------------------------------
+
+void FunctionPopup_Impl::Select()
+{
+ nSelected = GetCurItemId();
+}
+*/
+
+
+
+struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl
+{
+ Point maPos;
+ Size maSize;
+ bool mbSigned;
+ Image maImage;
+};
+
+
+XmlSecStatusBarControl::XmlSecStatusBarControl( USHORT _nId, StatusBar& _rStb, SfxBindings& _rBind )
+ :SfxStatusBarControl( _nId, _rStb, _rBind )
+
+ ,mpImpl( new XmlSecStatusBarControl_Impl )
+{
+ mpImpl->mbSigned = false;
+// pImp->maImage = Image( ResId( RID_SVXBMP_POSITION, DIALOG_MGR() ) );
+}
+
+XmlSecStatusBarControl::~XmlSecStatusBarControl()
+{
+ delete mpImpl;
+}
+
+void XmlSecStatusBarControl::StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
+{
+ GetStatusBar().SetHelpText( GetId(), String() ); // necessary ?
+ GetStatusBar().SetHelpId( GetId(), nSID ); // necessary ?
+
+ if( SFX_ITEM_AVAILABLE != eState )
+ {
+ mpImpl->mbSigned = false;
+ }
+ else if( pState->ISA( SfxBoolItem ) )
+ {
+ mpImpl->mbSigned = ( ( SfxBoolItem* ) pState )->GetValue();
+ }
+ else
+ {
+ DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" );
+ mpImpl->mbSigned = false;
+ }
+
+ if( GetStatusBar().AreItemsVisible() ) // necessary ?
+ GetStatusBar().SetItemData( GetId(), 0 );
+
+ GetStatusBar().SetItemText( GetId(), String() ); // necessary ?
+}
+
+void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt )
+{
+ // can / has to be done when integrated in Office!
+// if( rCEvt.GetCommand() == .... )
+ if( false )
+ {
+// GetBindings().GetDispatcher()->Execute( SID_PSZ_FUNCTION, SFX_CALLMODE_RECORD, &aItem, 0L );
+ }
+ else
+ SfxStatusBarControl::Command( rCEvt );
+}
+
+void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt )
+{
+ OutputDevice* pDev = rUsrEvt.GetDevice();
+ DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." );
+ const Rectangle& rRect = rUsrEvt.GetRect();
+ StatusBar& rBar = GetStatusBar();
+ Point aItemPos = rBar.GetItemTextPos( GetId() );
+ Color aOldLineColor = pDev->GetLineColor();
+ Color aOldFillColor = pDev->GetFillColor();
+
+ // just 4 testing until we've got a bitmap
+ pDev->SetLineColor();
+ pDev->SetFillColor( pDev->GetBackground().GetColor() );
+
+ String s( String::CreateFromAscii( mpImpl->mbSigned? "X" : "-" ) );
+ pDev->DrawRect( rRect );
+ pDev->DrawText( Point( rRect.Left() + rRect.GetWidth() / 2 - pDev->GetTextWidth( s ) / 2, aItemPos.Y() ), s );
+
+ pDev->SetLineColor( aOldLineColor );
+ pDev->SetFillColor( aOldFillColor );
+}
+
diff --git a/xmlsecurity/source/framework/buffernode.cxx b/xmlsecurity/source/framework/buffernode.cxx
new file mode 100644
index 000000000000..148fb3709e0a
--- /dev/null
+++ b/xmlsecurity/source/framework/buffernode.cxx
@@ -0,0 +1,1313 @@
+/*************************************************************************
+ *
+ * $RCSfile: buffernode.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "elementmark.hxx"
+#include "elementcollector.hxx"
+#include "buffernode.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_CONSTOFSECURITYID_HPP_
+#include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssxw = com::sun::star::xml::wrapper;
+namespace cssxc = com::sun::star::xml::crypto;
+
+BufferNode::BufferNode( const cssu::Reference< cssxw::XXMLElementWrapper >& xXMLElement )
+ :m_xXMLElement(xXMLElement),
+ m_pParent(NULL),
+ m_pBlocker(NULL),
+ m_bAllReceived(false)
+{
+}
+
+bool BufferNode::isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const
+/****** BufferNode/isECOfBeforeModifyIncluded ********************************
+ *
+ * NAME
+ * isECOfBeforeModifyIncluded -- checks whether there is some
+ * ElementCollector on this BufferNode, that has BEFORE-MODIFY priority.
+ *
+ * SYNOPSIS
+ * bExist = isECOfBeforeModifyIncluded(nIgnoredSecurityId);
+ *
+ * FUNCTION
+ * checks each ElementCollector on this BufferNode, if all following
+ * conditions are satisfied, then returns true:
+ * 1. the ElementCollector's priority is PRI_BEFOREMODIFY;
+ * 2. the ElementCollector's securityId can't be ignored.
+ * otherwise, returns false.
+ *
+ * INPUTS
+ * nIgnoredSecurityId - the security Id to be ignored. If it equals
+ * to UNDEFINEDSECURITYID, then no security Id
+ * will be ignored.
+ *
+ * RESULT
+ * bExist - true if a match found, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+ std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
+
+ for( ; ii != m_vElementCollectors.end() ; ++ii )
+ {
+ ElementCollector* pElementCollector = (ElementCollector*)*ii;
+
+ if ((nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
+ pElementCollector->getSecurityId() != nIgnoredSecurityId) &&
+ (pElementCollector->getPriority() == cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY))
+ {
+ rc = true;
+ break;
+ }
+ }
+
+ return rc;
+}
+
+void BufferNode::setReceivedAll()
+/****** BufferNode/setReceiveAll *********************************************
+ *
+ * NAME
+ * setReceivedAll -- indicates that the element in this BufferNode has
+ * been compeletely bufferred.
+ *
+ * SYNOPSIS
+ * setReceivedAll();
+ *
+ * FUNCTION
+ * sets the all-received flag and launches ElementCollector's notify
+ * process.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bAllReceived = true;
+ elementCollectorNotify();
+}
+
+bool BufferNode::isAllReceived() const
+{
+ return m_bAllReceived;
+}
+
+void BufferNode::addElementCollector(const ElementCollector* pElementCollector)
+/****** BufferNode/addElementCollector ***************************************
+ *
+ * NAME
+ * addElementCollector -- adds a new ElementCollector to this BufferNode.
+ *
+ * SYNOPSIS
+ * addElementCollector(pElementCollector);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pElementCollector - the ElementCollector to be added
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_vElementCollectors.push_back( pElementCollector );
+ ((ElementCollector*)pElementCollector)->setBufferNode(this);
+}
+
+void BufferNode::removeElementCollector(const ElementCollector* pElementCollector)
+/****** BufferNode/removeElementCollector ************************************
+ *
+ * NAME
+ * removeElementCollector -- removes an ElementCollector from this
+ * BufferNode.
+ *
+ * SYNOPSIS
+ * removeElementCollector(pElementCollector);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pElementCollector - the ElementCollector to be removed
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const ElementCollector* >::iterator ii = m_vElementCollectors.begin();
+
+ for( ; ii != m_vElementCollectors.end() ; ++ii )
+ {
+ if( *ii == pElementCollector )
+ {
+ m_vElementCollectors.erase( ii );
+ ((ElementCollector*)pElementCollector)->setBufferNode(NULL);
+ break;
+ }
+ }
+}
+
+ElementMark* BufferNode::getBlocker() const
+{
+ return m_pBlocker;
+}
+
+void BufferNode::setBlocker(const ElementMark* pBlocker)
+/****** BufferNode/setBlocker ************************************************
+ *
+ * NAME
+ * setBlocker -- adds a blocker to this BufferNode.
+ *
+ * SYNOPSIS
+ * setBlocker(pBlocker);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pBlocker - the new blocker to be attached
+ *
+ * RESULT
+ * empty
+ *
+ * NOTES
+ * Because there is only one blocker permited for a BufferNode, so the
+ * old blocker on this BufferNode, if there is one, will be overcasted.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ OSL_ASSERT(!(m_pBlocker != NULL && pBlocker != NULL));
+
+ m_pBlocker = (ElementMark*)pBlocker;
+ if (m_pBlocker != NULL)
+ {
+ m_pBlocker->setBufferNode(this);
+ }
+}
+
+rtl::OUString BufferNode::printChildren() const
+/****** BufferNode/printChildren *********************************************
+ *
+ * NAME
+ * printChildren -- prints children information into a string.
+ *
+ * SYNOPSIS
+ * result = printChildren();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * result - the information string
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ rtl::OUString rc;
+ std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
+
+ for( ; ii != m_vElementCollectors.end() ; ++ii )
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BufID=" ));
+ rc += rtl::OUString::valueOf((*ii)->getBufferId());
+
+ if (((ElementCollector*)(*ii))->getModify())
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[M]" ));
+ }
+
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ",Pri=" ));
+
+ switch (((ElementCollector*)(*ii))->getPriority())
+ {
+ case cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY:
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BEFOREMODIFY" ));
+ break;
+ case cssxc::sax::ElementMarkPriority_PRI_AFTERMODIFY:
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AFTERMODIFY" ));
+ break;
+ default:
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UNKNOWN" ));
+ break;
+ }
+
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "(" ));
+ /*
+ if (((ElementCollector*)(*ii))->isInternalNotificationSuppressed())
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*IN-Suppressed* " ));
+ }
+ */
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SecID=" ));
+ rc += rtl::OUString::valueOf(((ElementCollector*)(*ii))->getSecurityId());
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ));
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
+ }
+
+ return rc;
+}
+
+bool BufferNode::hasAnything() const
+/****** BufferNode/hasAnything ***********************************************
+ *
+ * NAME
+ * hasAnything -- checks whether there is any ElementCollector or blocker
+ * on this BufferNode.
+ *
+ * SYNOPSIS
+ * bExist = hasAnything();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bExist - true if there is, false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return (m_pBlocker != NULL || m_vElementCollectors.size() > 0);
+}
+
+bool BufferNode::hasChildren() const
+/****** BufferNode/hasChildren ***********************************************
+ *
+ * NAME
+ * hasChildren -- checks whether this BufferNode has any child
+ * BufferNode.
+ *
+ * SYNOPSIS
+ * bExist = hasChildren();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bExist - true if there is, false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return (m_vChildren.size() > 0);
+}
+
+std::vector< const BufferNode* >* BufferNode::getChildren() const
+{
+ return new std::vector< const BufferNode* >( m_vChildren );
+}
+
+const BufferNode* BufferNode::getFirstChild() const
+/****** BufferNode/getFirstChild *********************************************
+ *
+ * NAME
+ * getFirstChild -- retrieves the first child BufferNode.
+ *
+ * SYNOPSIS
+ * child = getFirstChild();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * child - the first child BufferNode, or NULL if there is no child
+ * BufferNode.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* rc = NULL;
+
+ if (m_vChildren.size() > 0)
+ {
+ rc = (BufferNode*)m_vChildren.front();
+ }
+
+ return (const BufferNode*)rc;
+}
+
+void BufferNode::addChild(const BufferNode* pChild, sal_Int32 nPosition)
+/****** BufferNode/addChild(pChild,nPosition) ********************************
+ *
+ * NAME
+ * addChild -- inserts a child BufferNode at specific position.
+ *
+ * SYNOPSIS
+ * addChild(pChild, nPosition);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pChild - the child BufferNode to be added.
+ * nPosition - the position where the new child locates.
+ *
+ * RESULT
+ * empty
+ *
+ * NOTES
+ * If the nPosition is -1, then the new child BufferNode is appended
+ * at the end.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (nPosition == -1)
+ {
+ m_vChildren.push_back( pChild );
+ }
+ else
+ {
+ std::vector< const BufferNode* >::iterator ii = m_vChildren.begin();
+ ii += nPosition;
+ m_vChildren.insert(ii, pChild);
+ }
+}
+
+void BufferNode::addChild(const BufferNode* pChild)
+/****** BufferNode/addChild() ************************************************
+ *
+ * NAME
+ * addChild -- add a new child BufferNode.
+ *
+ * SYNOPSIS
+ * addChild(pChild);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pChild - the child BufferNode to be added.
+ *
+ * RESULT
+ * empty
+ *
+ * NOTES
+ * The new child BufferNode is appended at the end.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ addChild(pChild, -1);
+}
+
+void BufferNode::removeChild(const BufferNode* pChild)
+/****** BufferNode/removeChild ***********************************************
+ *
+ * NAME
+ * removeChild -- removes a child BufferNode from the children list.
+ *
+ * SYNOPSIS
+ * removeChild(pChild);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pChild - the child BufferNode to be removed
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const BufferNode* >::iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ if( *ii == pChild )
+ {
+ m_vChildren.erase( ii );
+ break;
+ }
+ }
+}
+
+sal_Int32 BufferNode::indexOfChild(const BufferNode* pChild) const
+/****** BufferNode/indexOfChild **********************************************
+ *
+ * NAME
+ * indexOfChild -- gets the index of a child BufferNode.
+ *
+ * SYNOPSIS
+ * index = indexOfChild(pChild);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pChild - the child BufferNode whose index to be gotten
+ *
+ * RESULT
+ * index - the index of that child BufferNode. If that child BufferNode
+ * is not found, -1 is returned.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ sal_Int32 nIndex = 0;
+ bool bFound = false;
+
+ std::vector< const BufferNode * >::const_iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ if( *ii == pChild )
+ {
+ bFound = true;
+ break;
+ }
+ nIndex++;
+ }
+
+ if (!bFound )
+ {
+ nIndex = -1;
+ }
+
+ return nIndex;
+}
+
+const BufferNode* BufferNode::childAt(sal_Int32 nIndex) const
+/****** BufferNode/childAt ***************************************************
+ *
+ * NAME
+ * childAt -- retrieves the child BufferNode at specific possition.
+ *
+ * SYNOPSIS
+ * child = childAt(nIndex);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * nIndex - the index of the child BufferNode to be retrieved
+ *
+ * RESULT
+ * child - the child BufferNode at index position, or NULL if the index
+ * is out of the range of children.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* rc = NULL;
+
+ if (nIndex < ((sal_Int32)m_vChildren.size()) && nIndex >= 0)
+ {
+ rc = (BufferNode*)m_vChildren[nIndex];
+ }
+
+ return (const BufferNode*)rc;
+}
+
+const BufferNode* BufferNode::getParent() const
+{
+ return m_pParent;
+}
+
+void BufferNode::setParent(const BufferNode* pParent)
+{
+ m_pParent = (BufferNode*)pParent;
+}
+
+const BufferNode* BufferNode::getNextSibling() const
+/****** BufferNode/getNextSibling ********************************************
+ *
+ * NAME
+ * getNextSibling -- retrieves the next sibling BufferNode.
+ *
+ * SYNOPSIS
+ * sibling = getNextSibling();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * sibling - the next sibling BufferNode, or NULL if there is none.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* rc = NULL;
+
+ if (m_pParent != NULL)
+ {
+ rc = (BufferNode*)m_pParent->getNextChild(this);
+ }
+
+ return (const BufferNode*)rc;
+}
+
+const BufferNode* BufferNode::isAncestor(const BufferNode* pDescendant) const
+/****** BufferNode/isAncestor ************************************************
+ *
+ * NAME
+ * isAncestor -- checks whether this BufferNode is an ancestor of another
+ * BufferNode.
+ *
+ * SYNOPSIS
+ * bIs = isAncestor(pDescendant);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pDescendant - the BufferNode to be checked as a descendant
+ *
+ * RESULT
+ * bIs - true if this BufferNode is an ancestor of the pDescendant,
+ * false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* rc = NULL;
+
+ if (pDescendant != NULL)
+ {
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ BufferNode* pChild = (BufferNode*)*ii;
+
+ if (pChild == pDescendant)
+ {
+ rc = pChild;
+ break;
+ }
+
+ if (pChild->isAncestor(pDescendant) != NULL)
+ {
+ rc = pChild;
+ break;
+ }
+ }
+ }
+
+ return (const BufferNode*)rc;
+}
+
+bool BufferNode::isPrevious(const BufferNode* pFollowing) const
+/****** BufferNode/isPrevious ************************************************
+ *
+ * NAME
+ * isPrevious -- checks whether this BufferNode is ahead of another
+ * BufferNode in the tree order.
+ *
+ * SYNOPSIS
+ * bIs = isPrevious(pFollowing);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pFollowing - the BufferNode to be checked as a following
+ *
+ * RESULT
+ * bIs - true if this BufferNode is ahead in the tree order, false
+ * otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+
+ BufferNode* pNextBufferNode = (BufferNode*)getNextNodeByTreeOrder();
+ while (pNextBufferNode != NULL)
+ {
+ if (pNextBufferNode == pFollowing)
+ {
+ rc = true;
+ break;
+ }
+
+ pNextBufferNode = (BufferNode*)(pNextBufferNode->getNextNodeByTreeOrder());
+ }
+
+ return rc;
+}
+
+const BufferNode* BufferNode::getNextNodeByTreeOrder() const
+/****** BufferNode/getNextNodeByTreeOrder ************************************
+ *
+ * NAME
+ * getNextNodeByTreeOrder -- retrieves the next BufferNode in the tree
+ * order.
+ *
+ * SYNOPSIS
+ * next = getNextNodeByTreeOrder();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * next - the BufferNode following this BufferNode in the tree order,
+ * or NULL if there is none.
+ *
+ * NOTES
+ * The "next" node in tree order is defined as:
+ * 1. If a node has children, then the first child is;
+ * 2. otherwise, if it has a following sibling, then this sibling node is;
+ * 3. otherwise, if it has a parent node, the the parent's next sibling
+ * node is;
+ * 4. otherwise, no "next" node exists.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ /*
+ * If this buffer node has m_vChildren, then return the first
+ * child.
+ */
+ if (hasChildren())
+ {
+ return getFirstChild();
+ }
+
+ /*
+ * Otherwise, it this buffer node has a following sibling,
+ * then return that sibling.
+ */
+ BufferNode* pNextSibling = (BufferNode*)getNextSibling();
+ if (pNextSibling != NULL)
+ {
+ return pNextSibling;
+ }
+
+ /*
+ * Otherwise, it this buffer node has parent, then return
+ * its parent's following sibling.
+ */
+ BufferNode* pNode = (BufferNode*)this;
+ BufferNode* pParent;
+ BufferNode* pNextSiblingParent = NULL;
+
+ do
+ {
+ if (pNode == NULL)
+ {
+ break;
+ }
+
+ pParent = (BufferNode*)pNode->getParent();
+ if (pParent != NULL)
+ {
+ pNextSiblingParent = (BufferNode*)pParent->getNextSibling();
+ }
+ pNode = pParent;
+
+ }while (pNextSiblingParent == NULL);
+
+ return pNextSiblingParent;
+}
+
+cssu::Reference< cssxw::XXMLElementWrapper > BufferNode::getXMLElement() const
+{
+ return m_xXMLElement;
+}
+
+void BufferNode::setXMLElement( const cssu::Reference< cssxw::XXMLElementWrapper >& xXMLElement )
+{
+ m_xXMLElement = xXMLElement;
+}
+
+void BufferNode::notifyBranch()
+/****** BufferNode/notifyBranch **********************************************
+ *
+ * NAME
+ * notifyBranch -- notifies each BufferNode in the branch of this
+ * BufferNode in the tree order.
+ *
+ * SYNOPSIS
+ * notifyBranch();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ BufferNode* pBufferNode = (BufferNode*)*ii;
+ pBufferNode->elementCollectorNotify();
+ pBufferNode->notifyBranch();
+ }
+}
+
+void BufferNode::notifyAncestor()
+/****** BufferNode/notifyAncestor ********************************************
+ *
+ * NAME
+ * notifyAncestor -- notifies each ancestor BufferNode through the parent
+ * link.
+ *
+ * SYNOPSIS
+ * notifyAncestor();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* pParent = m_pParent;
+ while (pParent != NULL)
+ {
+ pParent->notifyAncestor();
+ pParent = (BufferNode*)pParent->getParent();
+ }
+}
+
+void BufferNode::elementCollectorNotify()
+/****** BufferNode/elementCollectorNotify ************************************
+ *
+ * NAME
+ * elementCollectorNotify -- notifies this BufferNode.
+ *
+ * SYNOPSIS
+ * elementCollectorNotify();
+ *
+ * FUNCTION
+ * Notifies this BufferNode if the notification is not suppressed.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * child - the first child BufferNode, or NULL if there is no child
+ * BufferNode.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (m_vElementCollectors.size()>0)
+ {
+ cssxc::sax::ElementMarkPriority nMaxPriority = cssxc::sax::ElementMarkPriority_PRI_MINIMUM;
+ cssxc::sax::ElementMarkPriority nPriority;
+
+ /*
+ * get the max priority among ElementCollectors on this BufferNode
+ */
+ std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
+ for( ; ii != m_vElementCollectors.end() ; ++ii )
+ {
+ ElementCollector* pElementCollector = (ElementCollector*)*ii;
+ nPriority = pElementCollector->getPriority();
+ if (nPriority > nMaxPriority)
+ {
+ nMaxPriority = nPriority;
+ }
+ }
+
+ std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors );
+ ii = vElementCollectors.begin();
+
+ for( ; ii != vElementCollectors.end() ; ++ii )
+ {
+ ElementCollector* pElementCollector = (ElementCollector*)*ii;
+ nPriority = pElementCollector->getPriority();
+ bool bToModify = pElementCollector->getModify();
+
+ /*
+ * Only ElementCollector with the max priority can
+ * perform notify operation.
+ * Moreover, if any blocker exists in the subtree of
+ * this BufferNode, this ElementCollector can't do notify
+ * unless its priority is PRI_BEFOREMODIFY.
+ */
+ if (nPriority == nMaxPriority &&
+ (nPriority == cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY ||
+ !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId())))
+ {
+ /*
+ * If this ElementCollector will modify the bufferred element, then
+ * special attention must be paid.
+ *
+ * If there is any ElementCollector in the subtree or any ancestor
+ * ElementCollector with PRI_BEFPREMODIFY priority, this
+ * ElementCollector can't perform notify operation, otherwise, it
+ * will destroy the bufferred element, in turn, ElementCollectors
+ * mentioned above can't perform their mission.
+ */
+ //if (!(nMaxPriority == cssxc::sax::ElementMarkPriority_PRI_MODIFY &&
+ if (!(bToModify &&
+ (isECInSubTreeIncluded(pElementCollector->getSecurityId()) ||
+ isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId()))
+ ))
+ {
+ pElementCollector->notifyListener();
+ }
+ }
+ }
+ }
+}
+
+bool BufferNode::isECInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
+/****** BufferNode/isECInSubTreeIncluded *************************************
+ *
+ * NAME
+ * isECInSubTreeIncluded -- checks whether there is any ElementCollector
+ * in the branch of this BufferNode.
+ *
+ * SYNOPSIS
+ * bExist = isECInSubTreeIncluded(nIgnoredSecurityId);
+ *
+ * FUNCTION
+ * checks each BufferNode in the branch of this BufferNode, if there is
+ * an ElementCollector whose signatureId is not ignored, then return
+ * true, otherwise, false returned.
+ *
+ * INPUTS
+ * nIgnoredSecurityId - the security Id to be ignored. If it equals
+ * to UNDEFINEDSECURITYID, then no security Id
+ * will be ignored.
+ *
+ * RESULT
+ * bExist - true if a match found, false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+
+ std::vector< const ElementCollector* >::const_iterator jj = m_vElementCollectors.begin();
+
+ for( ; jj != m_vElementCollectors.end() ; ++jj )
+ {
+ ElementCollector* pElementCollector = (ElementCollector*)*jj;
+ if (nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
+ pElementCollector->getSecurityId() != nIgnoredSecurityId)
+ {
+ rc = true;
+ break;
+ }
+ }
+
+ if ( !rc )
+ {
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ BufferNode* pBufferNode = (BufferNode*)*ii;
+
+ if ( pBufferNode->isECInSubTreeIncluded(nIgnoredSecurityId))
+ {
+ rc = true;
+ break;
+ }
+ }
+ }
+
+ return rc;
+}
+
+bool BufferNode::isECOfBeforeModifyInAncestorIncluded(sal_Int32 nIgnoredSecurityId) const
+/****** BufferNode/isECOfBeforeModifyInAncestorIncluded **********************
+ *
+ * NAME
+ * isECOfBeforeModifyInAncestorIncluded -- checks whether there is some
+ * ancestor BufferNode which has ElementCollector with PRI_BEFPREMODIFY
+ * priority.
+ *
+ * SYNOPSIS
+ * bExist = isECOfBeforeModifyInAncestorIncluded(nIgnoredSecurityId);
+ *
+ * FUNCTION
+ * checks each ancestor BufferNode through the parent link, if there is
+ * an ElementCollector with PRI_BEFPREMODIFY priority and its
+ * signatureId is not ignored, then return true, otherwise, false
+ * returned.
+ *
+ * INPUTS
+ * nIgnoredSecurityId - the security Id to be ignored. If it equals
+ * to UNDEFINEDSECURITYID, then no security Id
+ * will be ignored.
+ *
+ * RESULT
+ * bExist - true if a match found, false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+
+ BufferNode* pParentNode = m_pParent;
+ while (pParentNode != NULL)
+ {
+ if (pParentNode->isECOfBeforeModifyIncluded(nIgnoredSecurityId))
+ {
+ rc = true;
+ break;
+ }
+
+ pParentNode = (BufferNode*)pParentNode->getParent();
+ }
+
+ return rc;
+}
+
+bool BufferNode::isBlockerInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
+/****** BufferNode/isBlockerInSubTreeIncluded ********************************
+ *
+ * NAME
+ * isBlockerInSubTreeIncluded -- checks whether there is some BufferNode
+ * which has blocker on it
+ *
+ * SYNOPSIS
+ * bExist = isBlockerInSubTreeIncluded(nIgnoredSecurityId);
+ *
+ * FUNCTION
+ * checks each BufferNode in the branch of this BufferNode, if one has
+ * a blocker on it, and the blocker's securityId is not ignored, then
+ * returns true; otherwise, false returns.
+ *
+ * INPUTS
+ * nIgnoredSecurityId - the security Id to be ignored. If it equals
+ * to UNDEFINEDSECURITYID, then no security Id
+ * will be ignored.
+ *
+ * RESULT
+ * bExist - true if a match found, false otherwise.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ BufferNode* pBufferNode = (BufferNode*)*ii;
+ ElementMark* pBlocker = pBufferNode->getBlocker();
+
+ if (pBlocker != NULL &&
+ (nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
+ pBlocker->getSecurityId() != nIgnoredSecurityId ))
+ {
+ rc = true;
+ break;
+ }
+
+ if (rc || pBufferNode->isBlockerInSubTreeIncluded(nIgnoredSecurityId))
+ {
+ rc = true;
+ break;
+ }
+ }
+
+ return rc;
+}
+
+const BufferNode* BufferNode::getNextChild(const BufferNode* pChild) const
+/****** BufferNode/getNextChild **********************************************
+ *
+ * NAME
+ * getNextChild -- get the next child BufferNode.
+ *
+ * SYNOPSIS
+ * nextChild = getNextChild();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pChild - the child BufferNode whose next node is retrieved.
+ *
+ * RESULT
+ * nextChild - the next child BufferNode after the pChild, or NULL if
+ * there is none.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* rc = NULL;
+ bool bChildFound = false;
+
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ if (bChildFound)
+ {
+ rc = (BufferNode*)*ii;
+ break;
+ }
+
+ if( *ii == pChild )
+ {
+ bChildFound = true;
+ }
+ }
+
+ return (const BufferNode*)rc;
+}
+
+
+void BufferNode::freeAllChildren()
+/****** BufferNode/freeAllChildren *******************************************
+ *
+ * NAME
+ * freeAllChildren -- free all his child BufferNode.
+ *
+ * SYNOPSIS
+ * freeAllChildren();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 30.03.2004 - the correct the memory leak bug
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+ for( ; ii != m_vChildren.end() ; ++ii )
+ {
+ BufferNode *pChild = (BufferNode *)(*ii);
+ pChild->freeAllChildren();
+ delete pChild;
+ }
+
+ m_vChildren.clear();
+}
diff --git a/xmlsecurity/source/framework/buffernode.hxx b/xmlsecurity/source/framework/buffernode.hxx
new file mode 100644
index 000000000000..c184ea8ba14f
--- /dev/null
+++ b/xmlsecurity/source/framework/buffernode.hxx
@@ -0,0 +1,175 @@
+/*************************************************************************
+ *
+ * $RCSfile: buffernode.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _BUFFERNODE_HXX
+#define _BUFFERNODE_HXX
+
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+
+#ifndef INCLUDED_VECTOR
+#include <vector>
+#define INCLUDED_VECTOR
+#endif
+
+class ElementMark;
+class ElementCollector;
+
+class BufferNode
+/****** buffernode.hxx/CLASS BufferNode ***************************************
+ *
+ * NAME
+ * BufferNode -- Class to maintain the tree of bufferred elements
+ *
+ * FUNCTION
+ * One BufferNode object represents a bufferred element in the document
+ * wrapper component.
+ * All BufferNode objects construct a tree which has the same structure
+ * of all bufferred elements. That is to say, if one bufferred element is
+ * an ancestor of another bufferred element, then the corresponding
+ * BufferNode objects are also in ancestor/descendant relationship.
+ * This class is used to manipulate the tree of bufferred elements.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /* the parent BufferNode */
+ BufferNode* m_pParent;
+
+ /* all child BufferNodes */
+ std::vector< const BufferNode* > m_vChildren;
+
+ /* all ElementCollector holding this BufferNode */
+ std::vector< const ElementCollector* > m_vElementCollectors;
+
+ /*
+ * the blocker holding this BufferNode, one BufferNode can have one
+ * blocker at most
+ */
+ ElementMark* m_pBlocker;
+
+ /*
+ * whether the element has completely bufferred by the document wrapper
+ * component
+ */
+ bool m_bAllReceived;
+
+ /* the XMLElementWrapper of the bufferred element */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > m_xXMLElement;
+
+private:
+ bool isECInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const;
+ bool isECOfBeforeModifyInAncestorIncluded(sal_Int32 nIgnoredSecurityId) const;
+ bool isBlockerInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const;
+ const BufferNode* getNextChild(const BufferNode* pChild) const;
+
+public:
+ explicit BufferNode(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement);
+ virtual ~BufferNode() {};
+
+ bool isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const;
+ void setReceivedAll();
+ bool isAllReceived() const;
+ void addElementCollector(const ElementCollector* pElementCollector);
+ void removeElementCollector(const ElementCollector* pElementCollector);
+ ElementMark* getBlocker() const;
+ void setBlocker(const ElementMark* pBlocker);
+ rtl::OUString printChildren() const;
+ bool hasAnything() const;
+ bool hasChildren() const;
+ std::vector< const BufferNode* >* getChildren() const;
+ const BufferNode* getFirstChild() const;
+ void addChild(const BufferNode* pChild, sal_Int32 nPosition);
+ void addChild(const BufferNode* pChild);
+ void removeChild(const BufferNode* pChild);
+ sal_Int32 indexOfChild(const BufferNode* pChild) const;
+ const BufferNode* childAt(sal_Int32 nIndex) const;
+ const BufferNode* getParent() const;
+ void setParent(const BufferNode* pParent);
+ const BufferNode* getNextSibling() const;
+ const BufferNode* isAncestor(const BufferNode* pDescendant) const;
+ bool isPrevious(const BufferNode* pFollowing) const;
+ const BufferNode* getNextNodeByTreeOrder() const;
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > getXMLElement() const;
+ void setXMLElement(const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement);
+ void notifyBranch();
+ void notifyAncestor();
+ void elementCollectorNotify();
+ void freeAllChildren();
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/decryptorimpl.cxx b/xmlsecurity/source/framework/decryptorimpl.cxx
new file mode 100644
index 000000000000..b56354a32e8e
--- /dev/null
+++ b/xmlsecurity/source/framework/decryptorimpl.cxx
@@ -0,0 +1,288 @@
+/*************************************************************************
+ *
+ * $RCSfile: decryptorimpl.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 "decryptorimpl.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_DECRYPTIONRESULT_HPP_
+#include <com/sun/star/xml/crypto/sax/DecryptionResult.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
+{
+ mxMSF = rxMSF;
+}
+
+DecryptorImpl::~DecryptorImpl()
+{
+}
+
+bool DecryptorImpl::checkReady() const
+/****** DecryptorImpl/checkReady *********************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the decryption.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the result listener is ready;
+ * 2. the EncryptionEngine is ready.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return (m_xResultListener.is() && EncryptionEngine::checkReady());
+}
+
+void DecryptorImpl::notifyResultListener() const
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** DecryptorImpl/notifyResultListener ***********************************
+ *
+ * NAME
+ * notifyResultListener -- notifies the listener about the decryption
+ * result.
+ *
+ * SYNOPSIS
+ * notifyResultListener( );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxc::sax::XDecryptionResultListener >
+ xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
+
+ xDecryptionResultListener->decrypted(
+ m_nSecurityId,
+ m_bOperationSucceed?(cssxc::sax::DecryptionResult_DECRYPTIONSUCCEED):
+ (cssxc::sax::DecryptionResult_DECRYPTIONFAIL));
+}
+
+void DecryptorImpl::startEngine( const cssu::Reference<
+ cssxc::XXMLEncryptionTemplate >&
+ xEncryptionTemplate)
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** DecryptorImpl/startEngine ********************************************
+ *
+ * NAME
+ * startEngine -- decrypts the encryption.
+ *
+ * SYNOPSIS
+ * startEngine( xEncryptionTemplate );
+ *
+ * FUNCTION
+ * decrypts the encryption element, then if succeeds, updates the link
+ * of old template element to the new encryption element in
+ * SAXEventKeeper.
+ *
+ * INPUTS
+ * xEncryptionTemplate - the encryption template to be decrypted.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement;
+ try
+ {
+ xDecryptedElement = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
+ }
+ catch( cssu::Exception& )
+ {
+ xDecryptedElement = NULL;
+ }
+
+ if (xDecryptedElement.is())
+ {
+ m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
+ m_bOperationSucceed = true;
+ }
+}
+
+/* XDecryptionResultBroadcaster */
+void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_xResultListener = listener;
+ tryToPerform();
+}
+
+void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XInitialization */
+void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ sal_Int32 nLength = aArguments.getLength();
+ OSL_ASSERT(nLength == 5);
+
+ rtl::OUString ouTempString;
+
+ aArguments[0] >>= ouTempString;
+ m_nSecurityId = ouTempString.toInt32();
+ aArguments[1] >>= m_xSAXEventKeeper;
+ aArguments[2] >>= ouTempString;
+ m_nIdOfTemplateEC = ouTempString.toInt32();
+ aArguments[3] >>= m_xXMLSecurityContext;
+ aArguments[4] >>= m_xXMLEncryption;
+}
+
+rtl::OUString DecryptorImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_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 DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL DecryptorImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return DecryptorImpl_getImplementationName();
+}
+sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return DecryptorImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return DecryptorImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/framework/decryptorimpl.hxx b/xmlsecurity/source/framework/decryptorimpl.hxx
new file mode 100644
index 000000000000..52e40f02b391
--- /dev/null
+++ b/xmlsecurity/source/framework/decryptorimpl.hxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * $RCSfile: decryptorimpl.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 _DECRYPTORIMPL_HXX
+#define _DECRYPTORIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XDECRYPTIONRESULTBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XDecryptionResultBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XDECRYPTIONRESULTLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XDecryptionResultListener.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 "encryptionengine.hxx"
+
+class DecryptorImpl : public cppu::ImplInheritanceHelper3
+<
+ EncryptionEngine,
+ com::sun::star::xml::crypto::sax::XDecryptionResultBroadcaster,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+>
+/****** DecryptorImpl.hxx/CLASS DecryptorImpl *********************************
+ *
+ * NAME
+ * DecryptorImpl -- decrypts an encryption
+ *
+ * FUNCTION
+ * Collects all resources for decrypting an encryption, then decrypts the
+ * encryption by invoking a xmlsec-based encryption bridge component.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XDecryptionResultBroadcaster,
+ * XInitialization, XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the Id of the encryption, which is used for the result listener to
+ * identify the encryption.
+ */
+ sal_Int32 m_nEncryptionId;
+
+ /*
+ * the decryption result,
+ * remembers whether the decryption succeeds.
+ */
+ bool m_bDecryptionSucceed;
+
+ virtual void notifyResultListener() const
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual bool checkReady() const;
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLEncryptionTemplate >&
+ xEncryptionTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+public:
+ explicit DecryptorImpl( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory >& rxMSF);
+ virtual ~DecryptorImpl();
+
+ /* XDecryptionResultBroadcaster */
+ virtual void SAL_CALL addDecryptionResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XDecryptionResultListener >&
+ listener )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeDecryptionResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XDecryptionResultListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* 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);
+
+ /* 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 DecryptorImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL DecryptorImpl_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/framework/elementcollector.cxx b/xmlsecurity/source/framework/elementcollector.cxx
new file mode 100644
index 000000000000..c9633e8720dc
--- /dev/null
+++ b/xmlsecurity/source/framework/elementcollector.cxx
@@ -0,0 +1,330 @@
+/*************************************************************************
+ *
+ * $RCSfile: elementcollector.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "elementmark.hxx"
+#include "elementcollector.hxx"
+#include "buffernode.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_CONSTOFSECURITYID_HPP_
+#include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssxc = com::sun::star::xml::crypto;
+
+ElementCollector::ElementCollector(
+ sal_Int32 nSecurityId,
+ sal_Int32 nBufferId,
+ cssxc::sax::ElementMarkPriority nPriority,
+ bool bToModify,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
+ xReferenceResolvedListener)
+ :ElementMark(nSecurityId, nBufferId),
+ m_nPriority(nPriority),
+ m_bToModify(bToModify),
+ m_xReferenceResolvedListener(xReferenceResolvedListener),
+ m_bAbleToNotify(false),
+ m_bNotified(false)
+/****** ElementCollector/ElementCollector *************************************
+ *
+ * NAME
+ * ElementCollector -- constructor method
+ *
+ * SYNOPSIS
+ * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
+ * xReferenceResolvedListener);
+ *
+ * FUNCTION
+ * construct an ElementCollector object.
+ *
+ * INPUTS
+ * nSecurityId - represents which security entity the buffer node is
+ * related with. Either a signature or an encryption is
+ * a security entity.
+ * nBufferId - the id of the element bufferred in the document
+ * wrapper component. The document wrapper component
+ * uses this id to search the particular bufferred
+ * element.
+ * nPriority - the priority value. ElementCollector with lower
+ * priority value can't notify until all ElementCollectors
+ * with higher priority value have notified.
+ * bToModify - A flag representing whether this ElementCollector
+ * notification will cause the modification of its working
+ * element.
+ * xReferenceResolvedListener
+ * - the listener that this ElementCollector notifies to.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_type = cssxc::sax::ElementMarkType_TYPEOFELEMENTCOLLECTOR;
+}
+
+/*
+bool ElementCollector::isInternalNotificationSuppressed() const
+{
+ return m_bInternalNotificationSuppressed;
+}
+*/
+
+cssxc::sax::ElementMarkPriority ElementCollector::getPriority() const
+{
+ return m_nPriority;
+}
+
+bool ElementCollector::getModify() const
+{
+ return m_bToModify;
+}
+
+void ElementCollector::notifyListener()
+/****** ElementCollector/notifyListener ***************************************
+ *
+ * NAME
+ * notifyListener -- enable the ability to notify the listener
+ *
+ * SYNOPSIS
+ * notifyListener();
+ *
+ * FUNCTION
+ * enable the ability to notify the listener and try to notify then.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bAbleToNotify = true;
+ doNotify();
+}
+
+bool ElementCollector::isAbleToNotify() const
+{
+ return m_bAbleToNotify;
+}
+
+void ElementCollector::setReferenceResolvedListener(
+ const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
+/****** ElementCollector/setReferenceResolvedListener *************************
+ *
+ * NAME
+ * setReferenceResolvedListener -- configures a listener for the buffer
+ * node in this object
+ *
+ * SYNOPSIS
+ * setReferenceResolvedListener(xReferenceResolvedListener);
+ *
+ * FUNCTION
+ * configures a new listener and try to notify then.
+ *
+ * INPUTS
+ * xReferenceResolvedListener - the new listener
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_xReferenceResolvedListener = xReferenceResolvedListener;
+ doNotify();
+}
+
+void ElementCollector::setSecurityId(sal_Int32 nSecurityId)
+/****** ElementCollector/setSecurityId ****************************************
+ *
+ * NAME
+ * setSecurityId -- configures the security Id of the buffer node
+ *
+ * SYNOPSIS
+ * setSecurityId(nSecurityId);
+ *
+ * FUNCTION
+ * configures the security Id and try to notify then
+ *
+ * INPUTS
+ * nSecurityId - the security Id
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_nSecurityId = nSecurityId;
+ doNotify();
+}
+
+void ElementCollector::doNotify()
+/****** ElementCollector/doNotify *********************************************
+ *
+ * NAME
+ * doNotify -- tries to notify the listener
+ *
+ * SYNOPSIS
+ * doNotify();
+ *
+ * FUNCTION
+ * notifies the listener when all below conditions are satisfied:
+ * the listener has not been notified;
+ * the notify right is granted;
+ * the listener has already been configured;
+ * the security id has already been configure
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (!m_bNotified &&
+ m_bAbleToNotify &&
+ m_xReferenceResolvedListener.is() &&
+ m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
+ {
+ m_bNotified = true;
+ m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
+ }
+}
+
+ElementCollector* ElementCollector::clone(
+ sal_Int32 nBufferId,
+ cssxc::sax::ElementMarkPriority nPriority ) const
+/****** ElementCollector/clone ************************************************
+ *
+ * NAME
+ * clone -- duplicates this ElementCollector object
+ *
+ * SYNOPSIS
+ * cloned = clone(nBufferId, nPriority);
+ *
+ * FUNCTION
+ * duplicates this ElementCollector object with new buffer Id, priority.
+ *
+ * INPUTS
+ * nBufferId - the buffer node's Id
+ * nPriority - the priority
+ *
+ * RESULT
+ * clone - a new ElementCollector
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ ElementCollector* pClonedOne
+ = new ElementCollector(m_nSecurityId,
+ nBufferId, nPriority, m_bToModify,
+ m_xReferenceResolvedListener);
+
+ if (m_bAbleToNotify)
+ {
+ pClonedOne->notifyListener();
+ }
+
+ if (m_pBufferNode != NULL)
+ {
+ m_pBufferNode->addElementCollector(pClonedOne);
+ }
+
+ return pClonedOne;
+}
+
diff --git a/xmlsecurity/source/framework/elementcollector.hxx b/xmlsecurity/source/framework/elementcollector.hxx
new file mode 100644
index 000000000000..703e51a2b039
--- /dev/null
+++ b/xmlsecurity/source/framework/elementcollector.hxx
@@ -0,0 +1,147 @@
+/*************************************************************************
+ *
+ * $RCSfile: elementcollector.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _ELEMENTCOLLECTOR_HXX
+#define _ELEMENTCOLLECTOR_HXX
+
+#include "elementmark.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_ELEMENTMARKPRIORITY_HPP_
+#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
+#endif
+
+class ElementCollector : public ElementMark
+/****** elementcollector.hxx/CLASS ElementCollector ***************************
+ *
+ * NAME
+ * ElementCollector -- Class to manipulate an element collector
+ *
+ * FUNCTION
+ * This class is derived from the ElementMark class. Beyond the function
+ * of the ElementMark class, this class also maintains the priority, and
+ * manages the notify process
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the notify priority, is one of following values:
+ * PRI_AFTERMODIFY - this ElementCollector will notify after all
+ * internal modifications have finished.
+ * PRI_BEFOREMODIFY - this ElementCollector must notify before any
+ * internal modification happens.
+ */
+ com::sun::star::xml::crypto::sax::ElementMarkPriority m_nPriority;
+
+ /*
+ * the modify flag, representing whether which elementcollector will
+ * modify its data.
+ */
+ bool m_bToModify;
+
+ /* the notify enable flag, see notifyListener method */
+ bool m_bAbleToNotify;
+
+ /* whether the listener has been notified */
+ bool m_bNotified;
+
+ /* the listener to be notified */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener > m_xReferenceResolvedListener;
+
+public:
+ ElementCollector(
+ sal_Int32 nSecurityId,
+ sal_Int32 nBufferId,
+ com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority,
+ bool bToModify,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
+ xReferenceResolvedListener);
+ virtual ~ElementCollector() {};
+
+ //bool isInternalNotificationSuppressed() const;
+ com::sun::star::xml::crypto::sax::ElementMarkPriority getPriority() const;
+ bool getModify() const;
+ void notifyListener();
+ bool isAbleToNotify() const;
+ void setReferenceResolvedListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
+ referenceResolvedListener);
+ void setSecurityId(sal_Int32 nSecurityId);
+ void doNotify();
+ ElementCollector* clone(
+ sal_Int32 nId,
+ com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority ) const;
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/elementmark.cxx b/xmlsecurity/source/framework/elementmark.cxx
new file mode 100644
index 000000000000..7d6c0596ecf6
--- /dev/null
+++ b/xmlsecurity/source/framework/elementmark.cxx
@@ -0,0 +1,136 @@
+/*************************************************************************
+ *
+ * $RCSfile: elementmark.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "elementmark.hxx"
+#include "buffernode.hxx"
+
+namespace cssxc = com::sun::star::xml::crypto;
+
+ElementMark::ElementMark(sal_Int32 nSecurityId, sal_Int32 nBufferId)
+ :m_nSecurityId(nSecurityId),
+ m_nBufferId(nBufferId),
+ m_pBufferNode(NULL),
+ m_type(cssxc::sax::ElementMarkType_TYPEOFELEMENTMARK)
+/****** ElementMark/ElementMark ***********************************************
+ *
+ * NAME
+ * ElementMark -- constructor method
+ *
+ * SYNOPSIS
+ * ElementMark(nSecurityId, nBufferId);
+ *
+ * FUNCTION
+ * construct an ElementMark object.
+ *
+ * INPUTS
+ * nSecurityId - represents which security entity the buffer node is
+ * related with. Either a signature or an encryption is
+ * a security entity.
+ * nBufferId - the id of the element bufferred in the document
+ * wrapper component. The document wrapper component
+ * uses this id to search the particular bufferred
+ * element.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+}
+
+BufferNode* ElementMark::getBufferNode() const
+{
+ return m_pBufferNode;
+}
+
+void ElementMark::setBufferNode(const BufferNode* pBufferNode)
+{
+ m_pBufferNode = (BufferNode*)pBufferNode;
+}
+
+sal_Int32 ElementMark::getSecurityId() const
+{
+ return m_nSecurityId;
+}
+
+void ElementMark::setSecurityId(sal_Int32 nSecurityId)
+{
+ m_nSecurityId = nSecurityId;
+}
+
+com::sun::star::xml::crypto::sax::ElementMarkType ElementMark::getType() const
+{
+ return m_type;
+}
+
+sal_Int32 ElementMark::getBufferId() const
+{
+ return m_nBufferId;
+}
+
+
+
diff --git a/xmlsecurity/source/framework/elementmark.hxx b/xmlsecurity/source/framework/elementmark.hxx
new file mode 100644
index 000000000000..e122f2645e0b
--- /dev/null
+++ b/xmlsecurity/source/framework/elementmark.hxx
@@ -0,0 +1,123 @@
+/*************************************************************************
+ *
+ * $RCSfile: elementmark.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _ELEMENTMARK_HXX
+#define _ELEMENTMARK_HXX
+
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_ELEMENTMARKTYPE_HPP_
+#include <com/sun/star/xml/crypto/sax/ElementMarkType.hpp>
+#endif
+
+class BufferNode;
+
+class ElementMark
+/****** elementmark.hxx/CLASS ElementMark *************************************
+ *
+ * NAME
+ * ElementMark -- Class to manipulate an element mark
+ *
+ * FUNCTION
+ * This class maintains the security id, buffer id and its type for a
+ * buffer node.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+protected:
+ /* the BufferNode maintained by this object */
+ BufferNode* m_pBufferNode;
+
+ /* the security Id */
+ sal_Int32 m_nSecurityId;
+
+ /* the buffer Id */
+ sal_Int32 m_nBufferId;
+
+ /*
+ * the type value, is one of following values:
+ * TYPEOFELEMENTMARK - the default value, represents an blocker if
+ * not changed
+ * TYPEOFELEMENTCOLLECTOR - represents an ElementCollector
+ */
+ com::sun::star::xml::crypto::sax::ElementMarkType m_type;
+
+public:
+ ElementMark(sal_Int32 nSecurityId, sal_Int32 nBufferId);
+ virtual ~ElementMark() {};
+
+ BufferNode* getBufferNode() const;
+ void setBufferNode(const BufferNode* pBufferNode);
+ sal_Int32 getSecurityId() const;
+ void setSecurityId(sal_Int32 nSecurityId);
+ com::sun::star::xml::crypto::sax::ElementMarkType getType() const;
+ sal_Int32 getBufferId() const;
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/encryptionengine.cxx b/xmlsecurity/source/framework/encryptionengine.cxx
new file mode 100644
index 000000000000..a2a7daeb0370
--- /dev/null
+++ b/xmlsecurity/source/framework/encryptionengine.cxx
@@ -0,0 +1,254 @@
+/*************************************************************************
+ *
+ * $RCSfile: encryptionengine.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "encryptionengine.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define ENCRYPTION_TEMPLATE "com.sun.star.xml.crypto.XMLEncryptionTemplate"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+EncryptionEngine::EncryptionEngine( )
+ :m_nIdOfBlocker(-1)
+{
+}
+
+bool EncryptionEngine::checkReady() const
+/****** EncryptionEngine/checkReady ******************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the main operation.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the main operation has't begun yet;
+ * 2. the key material is known;
+ * 3. the id of the template blocker is known;
+ * 4. both the key element and the encryption template
+ * are bufferred.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = true;
+
+ sal_Int32 nKeyInc = 0;
+ if (m_nIdOfKeyEC != 0)
+ {
+ nKeyInc = 1;
+ }
+
+ if (m_bMissionDone ||
+ m_nIdOfKeyEC == -1 ||
+ m_nIdOfBlocker == -1 ||
+ 1+nKeyInc > m_nNumOfResolvedReferences )
+ {
+ rc = false;
+ }
+
+ return rc;
+}
+
+void EncryptionEngine::tryToPerform( )
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** EncryptionEngine/tryToPerform ****************************************
+ *
+ * NAME
+ * tryToPerform -- tries to perform the encryption/decryption operation.
+ *
+ * SYNOPSIS
+ * tryToPerform( );
+ *
+ * FUNCTION
+ * if the situation is ready, perform following operations.
+ * 1. prepares a encryption template;
+ * 2. calls the encryption bridge component;
+ * 3. clears up all used resources;
+ * 4. notifies the result listener;
+ * 5. sets the "accomplishment" flag.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (checkReady())
+ {
+ const rtl::OUString sEncryptionTemplate (
+ RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_TEMPLATE ) );
+ cssu::Reference < cssxc::XXMLEncryptionTemplate > xEncryptionTemplate(
+ mxMSF->createInstance( sEncryptionTemplate ), cssu::UNO_QUERY );
+
+ OSL_ASSERT( xEncryptionTemplate.is() );
+
+ cssu::Reference< cssxw::XXMLElementWrapper > xXMLElement
+ = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC );
+
+ xEncryptionTemplate->setTemplate(xXMLElement);
+
+ startEngine( xEncryptionTemplate );
+
+ /*
+ * done
+ */
+ clearUp( );
+
+ notifyResultListener();
+
+ m_bMissionDone = true;
+ }
+}
+
+void EncryptionEngine::clearUp( ) const
+/****** EncryptionEngine/clearup *********************************************
+ *
+ * NAME
+ * clearUp -- clear up all resources used by this operation.
+ *
+ * SYNOPSIS
+ * clearUp( );
+ *
+ * FUNCTION
+ * cleaning resources up includes:
+ * 1. releases the ElementCollector for the encryption template element;
+ * 2. releases the Blocker for the encryption template element;
+ * 3. releases the ElementCollector for the key element, if there is one.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference < cssxc::sax::XReferenceResolvedBroadcaster >
+ xReferenceResolvedBroadcaster( m_xSAXEventKeeper, cssu::UNO_QUERY );
+
+ xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
+ m_nIdOfTemplateEC,
+ (const cssu::Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
+
+ m_xSAXEventKeeper->removeElementCollector(m_nIdOfTemplateEC);
+
+ if (m_nIdOfBlocker != -1)
+ {
+ m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
+ }
+
+ if (m_nIdOfKeyEC != 0 && m_nIdOfKeyEC != -1)
+ {
+ m_xSAXEventKeeper->removeElementCollector(m_nIdOfKeyEC);
+ }
+}
+
+/* XBlockerMonitor */
+void SAL_CALL EncryptionEngine::setBlockerId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+{
+ m_nIdOfBlocker = id;
+ tryToPerform();
+}
+
diff --git a/xmlsecurity/source/framework/encryptionengine.hxx b/xmlsecurity/source/framework/encryptionengine.hxx
new file mode 100644
index 000000000000..ca39d7939dd0
--- /dev/null
+++ b/xmlsecurity/source/framework/encryptionengine.hxx
@@ -0,0 +1,157 @@
+/*************************************************************************
+ *
+ * $RCSfile: encryptionengine.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _ENCRYPTIONENGINE_HXX
+#define _ENCRYPTIONENGINE_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XBLOCKERMONITOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XBlockerMonitor.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XKEYCOLLECTOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XMISSIONTAKER_HPP_
+#include <com/sun/star/xml/crypto/sax/XMissionTaker.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_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTION_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryption.hpp>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
+
+#include "securityengine.hxx"
+
+class EncryptionEngine : public cppu::ImplInheritanceHelper1
+<
+ SecurityEngine,
+ com::sun::star::xml::crypto::sax::XBlockerMonitor
+>
+/****** encryptionEngine.hxx/CLASS encryptionEngine ***************************
+ *
+ * NAME
+ * EncryptionEngine -- Base class of Encryptor and Decryptor
+ *
+ * FUNCTION
+ * Maintains common members and methods related with encryption.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XBlockerMonitor
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+protected:
+ /*
+ * the Encryption bridge component, which performs encrypt and decrypt
+ * operation based on xmlsec library.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLEncryption > m_xXMLEncryption;
+
+ /*
+ * the Id of template blocker.
+ */
+ sal_Int32 m_nIdOfBlocker;
+
+protected:
+ EncryptionEngine( );
+ virtual ~EncryptionEngine(){};
+
+ virtual void tryToPerform( )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void clearUp( ) const;
+ virtual bool checkReady() const;
+
+ /*
+ * starts the main function. This method will be implemented by any sub-class.
+ * For a Encryptor, it performs encryption operation;
+ * for a Decryptor, decryption operation is performed.
+ */
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLEncryptionTemplate >&
+ xEncryptionTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+ {};
+
+public:
+ /* XBlockerMonitor */
+ virtual void SAL_CALL setBlockerId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/encryptorimpl.cxx b/xmlsecurity/source/framework/encryptorimpl.cxx
new file mode 100644
index 000000000000..2006348335e4
--- /dev/null
+++ b/xmlsecurity/source/framework/encryptorimpl.cxx
@@ -0,0 +1,328 @@
+/*************************************************************************
+ *
+ * $RCSfile: encryptorimpl.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 "encryptorimpl.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_ENCRYPTIONRESULT_HPP_
+#include <com/sun/star/xml/crypto/sax/EncryptionResult.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.sax.Encryptor"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.EncryptorImpl"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+EncryptorImpl::EncryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
+{
+ m_nReferenceId = -1;
+ mxMSF = rxMSF;
+}
+
+EncryptorImpl::~EncryptorImpl()
+{
+}
+
+bool EncryptorImpl::checkReady() const
+/****** EncryptorImpl/checkReady *********************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the encryption.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the result listener is ready;
+ * 2. the EncryptionEngine is ready.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ sal_Int32 nKeyInc = 0;
+ if (m_nIdOfKeyEC != 0)
+ {
+ nKeyInc = 1;
+ }
+
+ return (m_xResultListener.is() &&
+ (m_nReferenceId != -1) &&
+ (2+nKeyInc == m_nNumOfResolvedReferences) &&
+ EncryptionEngine::checkReady());
+}
+
+void EncryptorImpl::notifyResultListener() const
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** DecryptorImpl/notifyResultListener ***********************************
+ *
+ * NAME
+ * notifyResultListener -- notifies the listener about the encryption
+ * result.
+ *
+ * SYNOPSIS
+ * notifyResultListener( );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxc::sax::XEncryptionResultListener >
+ xEncryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
+
+ xEncryptionResultListener->encrypted(
+ m_nSecurityId,
+ m_bOperationSucceed?(cssxc::sax::EncryptionResult_ENCRYPTIONSUCCEED):
+ (cssxc::sax::EncryptionResult_ENCRYPTIONFAIL));
+}
+
+void EncryptorImpl::startEngine( const cssu::Reference<
+ cssxc::XXMLEncryptionTemplate >&
+ xEncryptionTemplate)
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** EncryptorImpl/startEngine ********************************************
+ *
+ * NAME
+ * startEngine -- generates the encryption.
+ *
+ * SYNOPSIS
+ * startEngine( xEncryptionTemplate );
+ *
+ * FUNCTION
+ * generates the encryption element, then if succeeds, updates the link
+ * of old template element to the new encryption element in
+ * SAXEventKeeper.
+ *
+ * INPUTS
+ * xEncryptionTemplate - the encryption template to be encrypted.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference < cssxc::XXMLEncryptionTemplate > xResultTemplate;
+
+ cssu::Reference< cssxw::XXMLElementWrapper >
+ xXMLElement = m_xSAXEventKeeper->getElement( m_nReferenceId );
+ xEncryptionTemplate->setTarget(xXMLElement);
+
+ try
+ {
+ xResultTemplate = m_xXMLEncryption->encrypt(
+ xEncryptionTemplate, m_xXMLSecurityContext);
+ }
+ catch( cssu::Exception& )
+ {
+ xResultTemplate = NULL;
+ }
+
+ if (xResultTemplate.is())
+ {
+ cssu::Reference < cssxw::XXMLElementWrapper > xResultEncryption
+ = xResultTemplate->getTemplate();
+ m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultEncryption);
+
+ m_xSAXEventKeeper->setElement(m_nReferenceId, NULL);
+
+ m_bOperationSucceed = true;
+ }
+}
+
+/* XReferenceCollector */
+void SAL_CALL EncryptorImpl::setReferenceCount( sal_Int32 count )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ /*
+ * dummp method, because there is only one reference in
+ * encryption, different from signature.
+ * so the referenceNumber is always 1
+ */
+}
+
+void SAL_CALL EncryptorImpl::setReferenceId( sal_Int32 id )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_nReferenceId = id;
+}
+
+/* XEncryptionResultBroadcaster */
+void SAL_CALL EncryptorImpl::addEncryptionResultListener( const cssu::Reference< cssxc::sax::XEncryptionResultListener >& listener )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_xResultListener = listener;
+ tryToPerform();
+}
+
+void SAL_CALL EncryptorImpl::removeEncryptionResultListener( const cssu::Reference< cssxc::sax::XEncryptionResultListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XInitialization */
+void SAL_CALL EncryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ sal_Int32 nLength = aArguments.getLength();
+ OSL_ASSERT(nLength == 5);
+
+ rtl::OUString ouTempString;
+
+ aArguments[0] >>= ouTempString;
+ m_nSecurityId = ouTempString.toInt32();
+ aArguments[1] >>= m_xSAXEventKeeper;
+ aArguments[2] >>= ouTempString;
+ m_nIdOfTemplateEC = ouTempString.toInt32();
+ aArguments[3] >>= m_xXMLSecurityContext;
+ aArguments[4] >>= m_xXMLEncryption;
+}
+
+
+rtl::OUString EncryptorImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL EncryptorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL EncryptorImpl_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 EncryptorImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new EncryptorImpl(rSMgr);
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL EncryptorImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return EncryptorImpl_getImplementationName();
+}
+sal_Bool SAL_CALL EncryptorImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return EncryptorImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL EncryptorImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return EncryptorImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/framework/encryptorimpl.hxx b/xmlsecurity/source/framework/encryptorimpl.hxx
new file mode 100644
index 000000000000..4977cdb714a3
--- /dev/null
+++ b/xmlsecurity/source/framework/encryptorimpl.hxx
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * $RCSfile: encryptorimpl.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 _ENCRYPTORIMPL_HXX
+#define _ENCRYPTORIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XENCRYPTIONRESULTBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XEncryptionResultBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XENCRYPTIONRESULTLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XEncryptionResultListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATURECOLLECTOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceCollector.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_IMPLBASE4_HXX_
+#include <cppuhelper/implbase4.hxx>
+#endif
+
+#include "encryptionengine.hxx"
+
+class EncryptorImpl : public cppu::ImplInheritanceHelper4
+<
+ EncryptionEngine,
+ com::sun::star::xml::crypto::sax::XEncryptionResultBroadcaster,
+ com::sun::star::xml::crypto::sax::XReferenceCollector,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+>
+/****** EncryptorImpl.hxx/CLASS EncryptorImpl *********************************
+ *
+ * NAME
+ * EncryptorImpl -- generates an encryption
+ *
+ * FUNCTION
+ * Collects all resources for an encryption generation, then generates the
+ * encryption by invoking a xmlsec-based encryption bridge component.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XInitialization, XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the Id of the encryption, which is used for the result listener to
+ * identify the encryption.
+ */
+ sal_Int32 m_nEncryptionId;
+
+ /*
+ * the Id of the element to be encrypted.
+ */
+ sal_Int32 m_nReferenceId;
+
+ /*
+ * the decryption result,
+ * remembers whether the encryption succeeds.
+ */
+ bool m_bEncryptionSucceed;
+
+ virtual void notifyResultListener() const
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual bool checkReady() const;
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLEncryptionTemplate >&
+ xEncryptionTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+public:
+ explicit EncryptorImpl( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory >& rxMSF);
+ virtual ~EncryptorImpl();
+
+ /* XEncryptionResultBroadcaster */
+ virtual void SAL_CALL addEncryptionResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XEncryptionResultListener >&
+ listener )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeEncryptionResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XEncryptionResultListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* XReferenceCollector */
+ virtual void SAL_CALL setReferenceCount( sal_Int32 count )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setReferenceId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ /* 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);
+
+ /* 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 EncryptorImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL EncryptorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL EncryptorImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL EncryptorImpl_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/framework/makefile.mk b/xmlsecurity/source/framework/makefile.mk
new file mode 100644
index 000000000000..1ceaa7eb7b16
--- /dev/null
+++ b/xmlsecurity/source/framework/makefile.mk
@@ -0,0 +1,98 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+#
+# 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 = fw
+
+ENABLE_EXCEPTIONS = TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+
+# --- Files --------------------------------------------------------
+SLOFILES= \
+ $(SLO)$/buffernode.obj \
+ $(SLO)$/elementcollector.obj \
+ $(SLO)$/elementmark.obj \
+ $(SLO)$/securityengine.obj \
+ $(SLO)$/signatureengine.obj \
+ $(SLO)$/encryptionengine.obj \
+ $(SLO)$/signaturecreatorimpl.obj \
+ $(SLO)$/signatureverifierimpl.obj \
+ $(SLO)$/encryptorimpl.obj \
+ $(SLO)$/decryptorimpl.obj \
+ $(SLO)$/saxeventkeeperimpl.obj \
+ $(SLO)$/xmlencryptiontemplateimpl.obj \
+ $(SLO)$/xmlsignaturetemplateimpl.obj \
+ $(SLO)$/xsec_framework.obj
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx
new file mode 100644
index 000000000000..d926d049db90
--- /dev/null
+++ b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx
@@ -0,0 +1,1503 @@
+/*************************************************************************
+ *
+ * $RCSfile: saxeventkeeperimpl.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 "saxeventkeeperimpl.hxx"
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_CONSTOFSECURITYID_HPP_
+#include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
+#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 cssxw = com::sun::star::xml::wrapper;
+namespace cssxs = com::sun::star::xml::sax;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.sax.SAXEventKeeper"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SAXEventKeeperImpl"
+
+#define _USECOMPRESSEDDOCUMENTHANDLER
+
+SAXEventKeeperImpl::SAXEventKeeperImpl( )
+ :m_nNextElementMarkId(1),
+ m_pNewBlocker(NULL),
+ m_pCurrentBlockingBufferNode(NULL),
+ m_pRootBufferNode(NULL),
+ m_pCurrentBufferNode(NULL),
+ m_bIsForwarding(false),
+ m_bIsReleasing(false)
+{
+ m_vElementMarkBuffers.reserve(2);
+ m_vNewElementCollectors.reserve(2);
+ m_vReleasedElementMarkBuffers.reserve(2);
+}
+
+SAXEventKeeperImpl::~SAXEventKeeperImpl()
+{
+ /*
+ * delete the BufferNode tree
+ */
+ if (m_pRootBufferNode != NULL)
+ {
+ m_pRootBufferNode->freeAllChildren();
+ delete m_pRootBufferNode;
+ }
+
+ m_pRootBufferNode = m_pCurrentBufferNode = m_pCurrentBlockingBufferNode = NULL;
+
+ /*
+ * delete all unfreed ElementMarks
+ */
+ m_vNewElementCollectors.clear();
+ m_pNewBlocker = NULL;
+
+ std::vector< const ElementMark* >::const_iterator ii = m_vElementMarkBuffers.begin();
+ for( ; ii != m_vElementMarkBuffers.end(); ++ii )
+ {
+ delete (*ii);
+ }
+ m_vElementMarkBuffers.clear();
+}
+
+void SAXEventKeeperImpl::setCurrentBufferNode(BufferNode* pBufferNode)
+/****** SAXEventKeeperImpl/setCurrentBufferNode ******************************
+ *
+ * NAME
+ * setCurrentBufferNode -- set a new active BufferNode.
+ *
+ * SYNOPSIS
+ * setCurrentBufferNode( pBufferNode );
+ *
+ * FUNCTION
+ * connects this BufferNode into the BufferNode tree as a child of the
+ * current active BufferNode. Then makes this BufferNode as the current
+ * active BufferNode.
+ * If the previous active BufferNode points to the root
+ * BufferNode, which means that no buffering operation was proceeding,
+ * then notifies the status change listener that buffering operation
+ * will begin at once.
+ *
+ * INPUTS
+ * pBufferNode - a BufferNode which will be the new active BufferNode
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (pBufferNode != m_pCurrentBufferNode)
+ {
+ if ( m_pCurrentBufferNode == m_pRootBufferNode &&
+ m_xSAXEventKeeperStatusChangeListener.is())
+ {
+ m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(sal_True);
+ }
+
+ if (pBufferNode->getParent() == NULL)
+ {
+ m_pCurrentBufferNode->addChild(pBufferNode);
+ pBufferNode->setParent(m_pCurrentBufferNode);
+ }
+
+ m_pCurrentBufferNode = pBufferNode;
+ }
+}
+
+BufferNode* SAXEventKeeperImpl::addNewElementMarkBuffers()
+/****** SAXEventKeeperImpl/addNewElementMarkBuffers **************************
+ *
+ * NAME
+ * addNewElementMarkBuffers -- add new ElementCollectors and new Blocker.
+ *
+ * SYNOPSIS
+ * pBufferNode = addNewElementMarkBuffers( );
+ *
+ * FUNCTION
+ * if there are new ElementCollector or new Blocker to be added, then
+ * connect all of them with the current BufferNode. In case of the
+ * current BufferNode doesn't exist, creates one.
+ * Clears up the new ElementCollector list and the new Blocker pointer.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * pBufferNode - the BufferNode that has been connected with both new
+ * ElementCollectors and new Blocker.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* pBufferNode = NULL;
+
+ if ( (m_vNewElementCollectors.size()>0) ||
+ (m_pNewBlocker != NULL))
+ {
+ /*
+ * When the current BufferNode is right pointing to the current
+ * working element in the XMLDocumentWrapper component, then
+ * no new BufferNode is needed to create.
+ * This situation can only happen in the "Forwarding" mode.
+ */
+ if ( (m_pCurrentBufferNode != NULL) &&
+ (m_xXMLDocument->isCurrent(m_pCurrentBufferNode->getXMLElement())))
+ {
+ pBufferNode = m_pCurrentBufferNode;
+ }
+ else
+ {
+ pBufferNode = new BufferNode(m_xXMLDocument->getCurrentElement());
+ }
+
+ if (m_pNewBlocker != NULL)
+ {
+ pBufferNode->setBlocker(m_pNewBlocker);
+
+ /*
+ * If no blocking before, then notify the status change listener that
+ * the SAXEventKeeper has entered "blocking" status, during which, no
+ * SAX events will be forwarded to the next document handler.
+ */
+ if (m_pCurrentBlockingBufferNode == NULL)
+ {
+ m_pCurrentBlockingBufferNode = pBufferNode;
+
+ if (m_xSAXEventKeeperStatusChangeListener.is())
+ {
+ m_xSAXEventKeeperStatusChangeListener->blockingStatusChanged(sal_True);
+ }
+ }
+
+ m_pNewBlocker = NULL;
+ }
+
+ if (m_vNewElementCollectors.size()>0)
+ {
+ std::vector< const ElementCollector* >::const_iterator ii = m_vNewElementCollectors.begin();
+
+ for( ; ii != m_vNewElementCollectors.end(); ++ii )
+ {
+ pBufferNode->addElementCollector(*ii);
+ }
+
+ m_vNewElementCollectors.clear();
+ }
+ }
+
+ return pBufferNode;
+}
+
+ElementMark* SAXEventKeeperImpl::findElementMarkBuffer(sal_Int32 nId) const
+/****** SAXEventKeeperImpl/findElementMarkBuffer *****************************
+ *
+ * NAME
+ * findElementMarkBuffer -- finds an ElementMark.
+ *
+ * SYNOPSIS
+ * pElementMark = findElementMarkBuffer( nId );
+ *
+ * FUNCTION
+ * searches an ElementMark with the particular Id in the ElementMark
+ * list.
+ *
+ * INPUTS
+ * nId - the Id of the ElementMark to be searched.
+ *
+ * RESULT
+ * pElementMark - the ElementMark with the particular Id, or NULL when
+ * no such Id exists.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ ElementMark* pElementMark = NULL;
+
+ std::vector< const ElementMark* >::const_iterator ii = m_vElementMarkBuffers.begin();
+
+ for( ; ii != m_vElementMarkBuffers.end(); ++ii )
+ {
+ if ( nId == (*ii)->getBufferId())
+ {
+ pElementMark = (ElementMark*)*ii;
+ break;
+ }
+ }
+
+ return pElementMark;
+}
+
+void SAXEventKeeperImpl::removeElementMarkBuffer(sal_Int32 nId)
+/****** SAXEventKeeperImpl/removeElementMarkBuffer ***************************
+ *
+ * NAME
+ * removeElementMarkBuffer -- removes an ElementMark
+ *
+ * SYNOPSIS
+ * removeElementMarkBuffer( nId );
+ *
+ * FUNCTION
+ * removes an ElementMark with the particular Id in the ElementMark list.
+ *
+ * INPUTS
+ * nId - the Id of the ElementMark to be removed.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const ElementMark* >::iterator ii = m_vElementMarkBuffers.begin();
+
+ for( ; ii != m_vElementMarkBuffers.end(); ++ii )
+ {
+ if ( nId == (*ii)->getBufferId())
+ {
+ /*
+ * checks whether this ElementMark still in the new ElementCollect array
+ */
+ std::vector< const ElementCollector* >::iterator jj = m_vNewElementCollectors.begin();
+ for( ; jj != m_vNewElementCollectors.end(); ++jj )
+ {
+ if ((*ii) == (*jj))
+ {
+ m_vNewElementCollectors.erase(jj);
+ break;
+ }
+ }
+
+ /*
+ * checks whether this ElementMark is the new Blocker
+ */
+ if ((*ii) == m_pNewBlocker)
+ {
+ m_pNewBlocker = NULL;
+ }
+
+ /*
+ * destory the ElementMark
+ */
+ delete (*ii);
+
+ m_vElementMarkBuffers.erase( ii );
+ break;
+ }
+ }
+}
+
+rtl::OUString SAXEventKeeperImpl::printBufferNode(
+ BufferNode* pBufferNode, sal_Int32 nIndent) const
+/****** SAXEventKeeperImpl/printBufferNode ***********************************
+ *
+ * NAME
+ * printBufferNode -- retrieves the information of a BufferNode and its
+ * branch.
+ *
+ * SYNOPSIS
+ * info = printBufferNode( pBufferNode, nIndent );
+ *
+ * FUNCTION
+ * all retrieved information includes:
+ * 1. whether it is the current BufferNode;
+ * 2. whether it is the current blocking BufferNode;
+ * 3. the name of the parent element;
+ * 4. the name of this element;
+ * 5. all ElementCollectors working on this BufferNode;
+ * 6. the Blocker working on this BufferNode;
+ * 7. all child BufferNodes' information.
+ *
+ * INPUTS
+ * pBufferNode - the BufferNode from where information will be retrieved.
+ * nIndent - how many space characters prefixed before the output
+ * message.
+ *
+ * RESULT
+ * info - the information string
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ rtl::OUString rc;
+
+ for ( int i=0; i<nIndent; ++i )
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
+ }
+
+ if (pBufferNode == m_pCurrentBufferNode)
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[%]" ));
+ }
+
+ if (pBufferNode == m_pCurrentBlockingBufferNode)
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[B]" ));
+ }
+
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
+ rc += m_xXMLDocument->getNodeName(pBufferNode->getXMLElement());
+
+ BufferNode* pParent = (BufferNode*)pBufferNode->getParent();
+ if (pParent != NULL)
+ {
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[" ));
+ rc += m_xXMLDocument->getNodeName(pParent->getXMLElement());
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "]" ));
+ }
+
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":EC=" ));
+ rc += pBufferNode->printChildren();
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " BR=" ));
+
+ ElementMark * pBlocker = pBufferNode->getBlocker();
+ if (pBlocker != NULL)
+ {
+ rc += rtl::OUString::valueOf( pBlocker->getBufferId() );
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "(SecId=" ));
+ rc += rtl::OUString::valueOf( pBlocker->getSecurityId() );
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ));
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
+ }
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n" ));
+
+ std::vector< const BufferNode* >* vChildren = pBufferNode->getChildren();
+ std::vector< const BufferNode* >::const_iterator jj = vChildren->begin();
+ for( ; jj != vChildren->end(); ++jj )
+ {
+ rc += printBufferNode((BufferNode *)*jj, nIndent+4);
+ }
+
+ delete vChildren;
+
+ return rc;
+}
+
+cssu::Sequence< cssu::Reference< cssxw::XXMLElementWrapper > >
+ SAXEventKeeperImpl::collectChildWorkingElement(BufferNode* pBufferNode) const
+/****** SAXEventKeeperImpl/collectChildWorkingElement ************************
+ *
+ * NAME
+ * collectChildWorkingElement -- collects a BufferNode's all child
+ * Elements.
+ *
+ * SYNOPSIS
+ * list = collectChildWorkingElement( pBufferNode );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * pBufferNode - the BufferNode whose child Elements will be collected.
+ *
+ * RESULT
+ * list - the child Elements list.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< const BufferNode* >* vChildren = pBufferNode->getChildren();
+
+ cssu::Sequence < cssu::Reference<
+ cssxw::XXMLElementWrapper > > aChildrenCollection ( vChildren->size());
+
+ std::vector< const BufferNode* >::const_iterator ii = vChildren->begin();
+
+ sal_Int32 nIndex = 0;
+ for( ; ii != vChildren->end(); ++ii )
+ {
+ aChildrenCollection[nIndex] = (*ii)->getXMLElement();
+ nIndex++;
+ }
+
+ delete vChildren;
+
+ return aChildrenCollection;
+}
+
+void SAXEventKeeperImpl::smashBufferNode(
+ BufferNode* pBufferNode, bool bClearRoot) const
+/****** SAXEventKeeperImpl/smashBufferNode ***********************************
+ *
+ * NAME
+ * smashBufferNode -- removes a BufferNode along with its working
+ * element.
+ *
+ * SYNOPSIS
+ * smashBufferNode( pBufferNode, bClearRoot );
+ *
+ * FUNCTION
+ * removes the BufferNode's working element from the DOM document, while
+ * reserves all ancestor paths for its child BufferNodes.
+ * when any of the BufferNode's ancestor element is useless, removes it
+ * too.
+ * removes the BufferNode from the BufferNode tree.
+ *
+ * INPUTS
+ * pBufferNode - the BufferNode to be removed
+ * bClearRoot - whether the root element also needs to be cleared up.
+ *
+ * RESULT
+ * empty
+ *
+ * NOTES
+ * when removeing a Blocker's BufferNode, the bClearRoot flag should be
+ * true. Because a Blocker can buffer many SAX events which are not used
+ * by any other ElementCollector or Blocker.
+ * When the bClearRoot is set to true, the root BufferNode will be first
+ * cleared, with a stop flag seting at the next Blocking BufferNode. This
+ * operation can delete all useless bufferred SAX events which are only
+ * needed by the Blocker to be deleted.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (!pBufferNode->hasAnything())
+ {
+ BufferNode* pParent = (BufferNode*)pBufferNode->getParent();
+
+ /*
+ * delete the XML data
+ */
+ if (pParent == m_pRootBufferNode)
+ {
+ bool bIsNotBlocking = (m_pCurrentBlockingBufferNode == NULL);
+ bool bIsBlockInside = false;
+ bool bIsBlockingAfterward = false;
+
+ /*
+ * If this is a blocker, then remove any out-element data
+ * which caused by blocking. The removal process will stop
+ * at the next blokcer to avoid removing any useful data.
+ */
+ if (bClearRoot)
+ {
+ cssu::Sequence< cssu::Reference< cssxw::XXMLElementWrapper > >
+ aChildElements = collectChildWorkingElement(m_pRootBufferNode);
+
+ /*
+ * the clearUselessData only clearup the content in the
+ * node, not the node itself.
+ */
+ m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(),
+ aChildElements,
+ bIsNotBlocking?(NULL):
+ (m_pCurrentBlockingBufferNode->getXMLElement()));
+
+ /*
+ * remove the node if it is empty, then if its parent is also
+ * empty, remove it, then if the next parent is also empty,
+ * remove it,..., until parent become null.
+ */
+ m_xXMLDocument->collapse( m_pRootBufferNode->getXMLElement() );
+ }
+
+ /*
+ * if blocking, check the relationship between this BufferNode and
+ * the current blocking BufferNode.
+ */
+ if ( !bIsNotBlocking )
+ {
+ /*
+ * the current blocking BufferNode is a descendant of this BufferNode.
+ */
+ bIsBlockInside = (NULL != pBufferNode->isAncestor(m_pCurrentBlockingBufferNode));
+
+ /*
+ * the current blocking BufferNode locates behind this BufferNode in tree
+ * order.
+ */
+ bIsBlockingAfterward = pBufferNode->isPrevious(m_pCurrentBlockingBufferNode);
+ }
+
+ /*
+ * this BufferNode's working element needs to be deleted only when
+ * 1. there is no blocking, or
+ * 2. the current blocking BufferNode is a descendant of this BufferNode,
+ * (then in the BufferNode's working element, the useless data before the blocking
+ * element should be deleted.) or
+ * 3. the current blocking BufferNode is locates behind this BufferNode in tree,
+ * (then the useless data between the blocking element and the working element
+ * should be deleted.).
+ * Otherwise, this working element should not be deleted.
+ */
+ if ( bIsNotBlocking || bIsBlockInside || bIsBlockingAfterward )
+ {
+ cssu::Sequence< cssu::Reference< cssxw::XXMLElementWrapper > >
+ aChildElements = collectChildWorkingElement(pBufferNode);
+
+ /*
+ * the clearUselessData only clearup the content in the
+ * node, not the node itself.
+ */
+ m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(),
+ aChildElements,
+ bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()):
+ (NULL));
+
+ /*
+ * remove the node if it is empty, then if its parent is also
+ * empty, remove it, then if the next parent is also empty,
+ * remove it,..., until parent become null.
+ */
+ m_xXMLDocument->collapse( pBufferNode->getXMLElement() );
+ }
+ }
+
+ sal_Int32 nIndex = pParent->indexOfChild(pBufferNode);
+
+ std::vector< const BufferNode* >* vChildren = pBufferNode->getChildren();
+ pParent->removeChild(pBufferNode);
+ pBufferNode->setParent(NULL);
+
+ std::vector< const BufferNode * >::const_iterator ii = vChildren->begin();
+ for( ; ii != vChildren->end(); ++ii )
+ {
+ ((BufferNode *)(*ii))->setParent(pParent);
+ pParent->addChild(*ii, nIndex);
+ nIndex++;
+ }
+
+ delete vChildren;
+
+ /*
+ * delete the BufferNode
+ */
+ delete pBufferNode;
+ }
+}
+
+BufferNode* SAXEventKeeperImpl::findNextBlockingBufferNode(
+ BufferNode* pStartBufferNode) const
+/****** SAXEventKeeperImpl/findNextBlockingBufferNode ************************
+ *
+ * NAME
+ * findNextBlockingBufferNode -- finds the next blocking BufferNode
+ * behind the particular BufferNode.
+ *
+ * SYNOPSIS
+ * pBufferNode = findNextBlockingBufferNode( pStartBufferNode );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * pStartBufferNode - the BufferNode from where to search the next
+ * blocking BufferNode.
+ *
+ * RESULT
+ * pBufferNode - the next blocking BufferNode, or NULL if no such
+ * BufferNode exists.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* pNext = NULL;
+
+ if (pStartBufferNode != NULL)
+ {
+ pNext = pStartBufferNode;
+
+ while (NULL != (pNext = (BufferNode*)pNext->getNextNodeByTreeOrder()))
+ {
+ if (pNext->getBlocker() != NULL)
+ {
+ break;
+ }
+ }
+ }
+
+ return pNext;
+}
+
+void SAXEventKeeperImpl::diffuse(BufferNode* pBufferNode) const
+/****** SAXEventKeeperImpl/diffuse *******************************************
+ *
+ * NAME
+ * diffuse -- diffuse the notification.
+ *
+ * SYNOPSIS
+ * diffuse( pBufferNode );
+ *
+ * FUNCTION
+ * diffuse the collecting completion notification from the specific
+ * BufferNode along its parent link, until an ancestor which is not
+ * completely received is met.
+ *
+ * INPUTS
+ * pBufferNode - the BufferNode from which the notification will be
+ * diffused.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ BufferNode* pParent = pBufferNode;
+
+ while(pParent->isAllReceived())
+ {
+ pParent->elementCollectorNotify();
+ pParent = (BufferNode*)pParent->getParent();
+ }
+}
+
+void SAXEventKeeperImpl::releaseElementMarkBuffer()
+/****** SAXEventKeeperImpl/releaseElementMarkBuffer **************************
+ *
+ * NAME
+ * releaseElementMarkBuffer -- releases useless ElementMarks
+ *
+ * SYNOPSIS
+ * releaseElementMarkBuffer( );
+ *
+ * FUNCTION
+ * releases each ElementMark in the releasing list
+ * m_vReleasedElementMarkBuffers.
+ * The operation differs between an ElementCollector and a Blocker.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bIsReleasing = true;
+ while (m_vReleasedElementMarkBuffers.size()>0)
+ {
+ std::vector< sal_Int32 >::iterator pId = m_vReleasedElementMarkBuffers.begin();
+ sal_Int32 nId = *pId;
+ m_vReleasedElementMarkBuffers.erase( pId );
+
+ ElementMark* pElementMark = findElementMarkBuffer(nId);
+
+ if (pElementMark != NULL)
+ {
+ if (cssxc::sax::ElementMarkType_TYPEOFELEMENTCOLLECTOR
+ == pElementMark->getType())
+ /*
+ * it is a EC
+ */
+ {
+ ElementCollector* pElementCollector = (ElementCollector*)pElementMark;
+
+ cssxc::sax::ElementMarkPriority nPriority = pElementCollector->getPriority();
+ bool bToModify = pElementCollector->getModify();
+
+ /*
+ * Delete the EC from the buffer node.
+ */
+ BufferNode* pBufferNode = pElementCollector->getBufferNode();
+ pBufferNode->removeElementCollector(pElementCollector);
+
+ if ( nPriority == cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY)
+ {
+ pBufferNode->notifyBranch();
+ }
+
+ if (bToModify)
+ {
+ pBufferNode->notifyAncestor();
+ }
+
+ /*
+ * delete the ElementMark
+ */
+ pElementCollector = NULL;
+ pElementMark = NULL;
+ removeElementMarkBuffer(nId);
+
+ /*
+ * delete the BufferNode
+ */
+ diffuse(pBufferNode);
+ smashBufferNode(pBufferNode, false);
+ }
+ else
+ /*
+ * it is a Blocker
+ */
+ {
+ /*
+ * Delete the TH from the buffer node.
+ */
+ BufferNode *pBufferNode = pElementMark->getBufferNode();
+ pBufferNode->setBlocker(NULL);
+
+ /*
+ * If there is a following handler and no blocking now, then
+ * forward this event
+ */
+ if (m_pCurrentBlockingBufferNode == pBufferNode)
+ {
+ /*
+ * Before forwarding, the next blocking point needs to be
+ * found.
+ */
+ m_pCurrentBlockingBufferNode = findNextBlockingBufferNode(pBufferNode);
+
+ /*
+ * Forward the blocked events between these two STHs.
+ */
+ if (m_xNextHandler.is())
+ {
+ BufferNode* pTempCurrentBufferNode = m_pCurrentBufferNode;
+ BufferNode* pTempCurrentBlockingBufferNode = m_pCurrentBlockingBufferNode;
+
+ m_pCurrentBufferNode = pBufferNode;
+ m_pCurrentBlockingBufferNode = NULL;
+
+ m_bIsForwarding = true;
+
+ m_xXMLDocument->generateSAXEvents(
+ m_xNextHandler,
+ this,
+ pBufferNode->getXMLElement(),
+ (pTempCurrentBlockingBufferNode == NULL)?NULL:(pTempCurrentBlockingBufferNode->getXMLElement()));
+
+ m_bIsForwarding = false;
+
+ m_pCurrentBufferNode = pTempCurrentBufferNode;
+ if (m_pCurrentBlockingBufferNode == NULL)
+ {
+ m_pCurrentBlockingBufferNode = pTempCurrentBlockingBufferNode;
+ }
+ }
+
+ if (m_pCurrentBlockingBufferNode == NULL &&
+ m_xSAXEventKeeperStatusChangeListener.is())
+ {
+ m_xSAXEventKeeperStatusChangeListener->blockingStatusChanged(sal_False);
+ }
+ }
+
+ /*
+ * delete the ElementMark
+ */
+ pElementMark = NULL;
+ removeElementMarkBuffer(nId);
+
+ /*
+ * delete the BufferNode
+ */
+ diffuse(pBufferNode);
+ smashBufferNode(pBufferNode, true);
+ }
+ }
+ }
+
+ m_bIsReleasing = false;
+
+ if (!m_pRootBufferNode->hasAnything() &&
+ !m_pRootBufferNode->hasChildren() &&
+ m_xSAXEventKeeperStatusChangeListener.is())
+ {
+ m_xSAXEventKeeperStatusChangeListener->bufferStatusChanged(sal_True);
+ }
+}
+
+void SAXEventKeeperImpl::markElementMarkBuffer(sal_Int32 nId)
+/****** SAXEventKeeperImpl/markElementMarkBuffer *****************************
+ *
+ * NAME
+ * markElementMarkBuffer -- marks an ElementMark to be released
+ *
+ * SYNOPSIS
+ * markElementMarkBuffer( nId );
+ *
+ * FUNCTION
+ * puts the ElementMark with the particular Id into the releasing list,
+ * checks whether the releasing process is runing, if not then launch
+ * this process.
+ *
+ * INPUTS
+ * nId - the Id of the ElementMark which will be released
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_vReleasedElementMarkBuffers.push_back( nId );
+ if ( !m_bIsReleasing )
+ {
+ releaseElementMarkBuffer();
+ }
+}
+
+sal_Int32 SAXEventKeeperImpl::createElementCollector(
+ sal_Int32 nSecurityId,
+ cssxc::sax::ElementMarkPriority nPriority,
+ bool bModifyElement,
+ const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
+/****** SAXEventKeeperImpl/createElementCollector ****************************
+ *
+ * NAME
+ * createElementCollector -- creates a new ElementCollector on the
+ * incoming element.
+ *
+ * SYNOPSIS
+ * nId = createElementCollector( nSecurityId, nPriority,
+ * bModifyElement,
+ * xReferenceResolvedListener );
+ *
+ * FUNCTION
+ * allocs a new Id, then create an ElementCollector with this Id value.
+ * Add the new created ElementCollector to the new ElementCollecotor list.
+ *
+ * INPUTS
+ * nSecurityId - the security Id of the new ElementCollector
+ * nPriority - the prirority of the new ElementCollector
+ * bModifyElement -whether this BufferNode will modify the content of
+ * the corresponding element it works on
+ * xReferenceResolvedListener - the listener for the new ElementCollector.
+ *
+ * RESULT
+ * nId - the Id of the new ElementCollector
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ sal_Int32 nId = m_nNextElementMarkId;
+ m_nNextElementMarkId ++;
+
+ ElementCollector* pElementCollector
+ = new ElementCollector(
+ nSecurityId,
+ nId,
+ nPriority,
+ bModifyElement,
+ xReferenceResolvedListener);
+
+ m_vElementMarkBuffers.push_back( pElementCollector );
+
+ /*
+ * All the new EC to initial EC array.
+ */
+ m_vNewElementCollectors.push_back( pElementCollector );
+
+ return nId;
+}
+
+
+sal_Int32 SAXEventKeeperImpl::createBlocker(sal_Int32 nSecurityId)
+/****** SAXEventKeeperImpl/createBlocker *************************************
+ *
+ * NAME
+ * createBlocker -- creates a new Blocker on the incoming element.
+ *
+ * SYNOPSIS
+ * nId = createBlocker( nSecurityId );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * nSecurityId - the security Id of the new Blocker
+ *
+ * RESULT
+ * nId - the Id of the new Blocker
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ sal_Int32 nId = m_nNextElementMarkId;
+ m_nNextElementMarkId ++;
+
+ OSL_ASSERT(m_pNewBlocker == NULL);
+
+ m_pNewBlocker = new ElementMark(nSecurityId, nId);
+ m_vElementMarkBuffers.push_back( m_pNewBlocker );
+
+ return nId;
+}
+
+/* XSAXEventKeeper */
+sal_Int32 SAL_CALL SAXEventKeeperImpl::addElementCollector( )
+ throw (cssu::RuntimeException)
+{
+ return createElementCollector(
+ cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID,
+ cssxc::sax::ElementMarkPriority_PRI_AFTERMODIFY,
+ false,
+ NULL);
+}
+
+void SAL_CALL SAXEventKeeperImpl::removeElementCollector( sal_Int32 id )
+ throw (cssu::RuntimeException)
+{
+ markElementMarkBuffer(id);
+}
+
+sal_Int32 SAL_CALL SAXEventKeeperImpl::addBlocker( )
+ throw (cssu::RuntimeException)
+{
+ return createBlocker(cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID);
+}
+
+void SAL_CALL SAXEventKeeperImpl::removeBlocker( sal_Int32 id )
+ throw (cssu::RuntimeException)
+{
+ markElementMarkBuffer(id);
+}
+
+sal_Bool SAL_CALL SAXEventKeeperImpl::isBlocking( )
+ throw (cssu::RuntimeException)
+{
+ return (m_pCurrentBlockingBufferNode != NULL);
+}
+
+cssu::Reference< cssxw::XXMLElementWrapper > SAL_CALL
+ SAXEventKeeperImpl::getElement( sal_Int32 id )
+ throw (cssu::RuntimeException)
+{
+ cssu::Reference< cssxw::XXMLElementWrapper > rc;
+
+ ElementMark* pElementMark = findElementMarkBuffer(id);
+ if (pElementMark != NULL)
+ {
+ rc = pElementMark->getBufferNode()->getXMLElement();
+ }
+
+ return rc;
+}
+
+void SAL_CALL SAXEventKeeperImpl::setElement(
+ sal_Int32 id,
+ const cssu::Reference< cssxw::XXMLElementWrapper >& aElement )
+ throw (cssu::RuntimeException)
+{
+ if (aElement.is())
+ {
+ m_xXMLDocument->rebuildIDLink(aElement);
+
+ ElementMark* pElementMark = findElementMarkBuffer(id);
+
+ if (pElementMark != NULL)
+ {
+ BufferNode* pBufferNode = pElementMark->getBufferNode();
+ if (pBufferNode != NULL)
+ {
+ bool bIsCurrent = m_xXMLDocument->isCurrent(pBufferNode->getXMLElement());
+ pBufferNode->setXMLElement(aElement);
+
+ if (bIsCurrent)
+ {
+ m_xXMLDocument->setCurrentElement(aElement);
+ }
+ }
+ }
+ }
+ else
+ {
+ removeElementCollector( id );
+ }
+}
+
+cssu::Reference< cssxs::XDocumentHandler > SAL_CALL SAXEventKeeperImpl::setNextHandler(
+ const cssu::Reference< cssxs::XDocumentHandler >& xNewHandler )
+ throw (cssu::RuntimeException)
+{
+ cssu::Reference< cssxs::XDocumentHandler > xOldHandler = m_xNextHandler;
+
+ m_xNextHandler = xNewHandler;
+ return xOldHandler;
+}
+
+rtl::OUString SAL_CALL SAXEventKeeperImpl::printBufferNodeTree()
+ throw (cssu::RuntimeException)
+{
+ rtl::OUString rc;
+
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ElementMarkBuffers: size = " ));
+ rc += rtl::OUString::valueOf((sal_Int32)m_vElementMarkBuffers.size());
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\nCurrentBufferNode: " ));
+ rc += m_xXMLDocument->getNodeName(m_pCurrentBufferNode->getXMLElement());
+ rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n" ));
+ rc += printBufferNode(m_pRootBufferNode, 0);
+
+ return rc;
+}
+
+cssu::Reference< cssxw::XXMLElementWrapper > SAL_CALL SAXEventKeeperImpl::getCurrentBlockingNode()
+ throw (cssu::RuntimeException)
+{
+ cssu::Reference< cssxw::XXMLElementWrapper > rc;
+
+ if (m_pCurrentBlockingBufferNode != NULL)
+ {
+ rc = m_pCurrentBlockingBufferNode->getXMLElement();
+ }
+
+ return rc;
+}
+
+/* XSecuritySAXEventKeeper */
+sal_Int32 SAL_CALL SAXEventKeeperImpl::addSecurityElementCollector(
+ cssxc::sax::ElementMarkPriority priority,
+ sal_Bool modifyElement )
+ throw (cssu::RuntimeException)
+{
+ return createElementCollector(
+ cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID,
+ priority,
+ modifyElement,
+ NULL);
+}
+
+sal_Int32 SAL_CALL SAXEventKeeperImpl::cloneElementCollector(
+ sal_Int32 referenceId,
+ cssxc::sax::ElementMarkPriority priority )
+ throw (cssu::RuntimeException)
+{
+ sal_Int32 nId = -1;
+
+ ElementCollector* pElementCollector = (ElementCollector*)findElementMarkBuffer(referenceId);
+ if (pElementCollector != NULL)
+ {
+ nId = m_nNextElementMarkId;
+ m_nNextElementMarkId ++;
+
+ ElementCollector* pClonedOne
+ = pElementCollector->clone(nId, priority);
+
+ /*
+ * add this EC into the security data buffer array.
+ */
+ m_vElementMarkBuffers.push_back(pClonedOne);
+
+ /*
+ * If the reference EC is still in initial EC array, add
+ * this cloned one into the initial EC array too.
+ */
+ if (pElementCollector->getBufferNode() == NULL)
+ {
+ m_vNewElementCollectors.push_back(pClonedOne);
+ }
+ }
+
+ return nId;
+}
+
+void SAL_CALL SAXEventKeeperImpl::setSecurityId( sal_Int32 id, sal_Int32 securityId )
+ throw (cssu::RuntimeException)
+{
+ ElementMark* pElementMark = findElementMarkBuffer(id);
+ if (pElementMark != NULL)
+ {
+ pElementMark->setSecurityId(securityId);
+ }
+}
+
+
+/* XReferenceResolvedBroadcaster */
+void SAL_CALL SAXEventKeeperImpl::addReferenceResolvedListener(
+ sal_Int32 referenceId,
+ const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& listener )
+ throw (cssu::RuntimeException)
+{
+ ElementCollector* pElementCollector = (ElementCollector*)findElementMarkBuffer(referenceId);
+ if (pElementCollector != NULL)
+ {
+ pElementCollector->setReferenceResolvedListener(listener);
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::removeReferenceResolvedListener(
+ sal_Int32 referenceId,
+ const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XSAXEventKeeperStatusChangeBroadcaster */
+void SAL_CALL SAXEventKeeperImpl::addXSAXEventKeeperStatusChangeListener(
+ const cssu::Reference< cssxc::sax::XSAXEventKeeperStatusChangeListener >& listener )
+ throw (cssu::RuntimeException)
+{
+ m_xSAXEventKeeperStatusChangeListener = listener;
+}
+
+void SAL_CALL SAXEventKeeperImpl::removeXSAXEventKeeperStatusChangeListener(
+ const cssu::Reference< cssxc::sax::XSAXEventKeeperStatusChangeListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XDocumentHandler */
+void SAL_CALL SAXEventKeeperImpl::startDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if ( m_xNextHandler.is())
+ {
+ m_xNextHandler->startDocument();
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::endDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if ( m_xNextHandler.is())
+ {
+ m_xNextHandler->endDocument();
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::startElement(
+ const rtl::OUString& aName,
+ const cssu::Reference< cssxs::XAttributeList >& xAttribs )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ /*
+ * If there is a following handler and no blocking now, then
+ * forward this event
+ */
+ if ((m_pCurrentBlockingBufferNode == NULL) &&
+ (m_xNextHandler.is()) &&
+ (!m_bIsForwarding) &&
+ (m_pNewBlocker == NULL))
+ {
+ m_xNextHandler->startElement(aName, xAttribs);
+ }
+
+ /*
+ * If not forwarding, buffer this startElement.
+ */
+ if (!m_bIsForwarding)
+ {
+ #ifndef _USECOMPRESSEDDOCUMENTHANDLER
+ m_xDocumentHandler->startElement(aName, xAttribs);
+ #else
+ 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);
+ }
+
+ m_xCompressedDocumentHandler->_startElement(aName, aAttributes);
+ #endif
+
+ }
+
+ BufferNode* pBufferNode = addNewElementMarkBuffers();
+ if (pBufferNode != NULL)
+ {
+ setCurrentBufferNode(pBufferNode);
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::endElement( const rtl::OUString& aName )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ sal_Bool bIsCurrent = m_xXMLDocument->isCurrent(m_pCurrentBufferNode->getXMLElement());
+
+ /*
+ * If there is a following handler and no blocking now, then
+ * forward this event
+ */
+ if ((m_pCurrentBlockingBufferNode == NULL) &&
+ (m_xNextHandler.is()) &&
+ (!m_bIsForwarding))
+ {
+ m_xNextHandler->endElement(aName);
+ }
+
+ if ((m_pCurrentBlockingBufferNode != NULL) ||
+ (m_pCurrentBufferNode != m_pRootBufferNode) ||
+ (!m_xXMLDocument->isCurrentElementEmpty()))
+ {
+ if (!m_bIsForwarding)
+ {
+ #ifndef _USECOMPRESSEDDOCUMENTHANDLER
+ m_xDocumentHandler->endElement(aName);
+ #else
+ m_xCompressedDocumentHandler->_endElement(aName);
+ #endif
+ }
+
+ /*
+ * If the current buffer node has not notified yet, and
+ * the current buffer node is waiting for the current element,
+ * then let it notify.
+ */
+ if (bIsCurrent && (m_pCurrentBufferNode != m_pRootBufferNode))
+ {
+ BufferNode* pOldCurrentBufferNode = m_pCurrentBufferNode;
+ m_pCurrentBufferNode = (BufferNode*)m_pCurrentBufferNode->getParent();
+
+ pOldCurrentBufferNode->setReceivedAll();
+
+ if ((m_pCurrentBufferNode == m_pRootBufferNode) &&
+ m_xSAXEventKeeperStatusChangeListener.is())
+ {
+ m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(sal_False);
+ }
+ }
+ }
+ else
+ {
+ if (!m_bIsForwarding)
+ {
+ m_xXMLDocument->removeCurrentElement();
+ }
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::characters( const rtl::OUString& aChars )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (!m_bIsForwarding)
+ {
+ if ((m_pCurrentBlockingBufferNode == NULL) && m_xNextHandler.is())
+ {
+ m_xNextHandler->characters(aChars);
+ }
+
+ if ((m_pCurrentBlockingBufferNode != NULL) ||
+ (m_pCurrentBufferNode != m_pRootBufferNode))
+ {
+ #ifndef _USECOMPRESSEDDOCUMENTHANDLER
+ m_xDocumentHandler->characters(aChars);
+ #else
+ m_xCompressedDocumentHandler->_characters(aChars);
+ #endif
+ }
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ characters( aWhitespaces );
+}
+
+void SAL_CALL SAXEventKeeperImpl::processingInstruction(
+ const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (!m_bIsForwarding)
+ {
+ if ((m_pCurrentBlockingBufferNode == NULL) && m_xNextHandler.is())
+ {
+ m_xNextHandler->processingInstruction(aTarget, aData);
+ }
+
+ if ((m_pCurrentBlockingBufferNode != NULL) ||
+ (m_pCurrentBufferNode != m_pRootBufferNode))
+ {
+ #ifndef _USECOMPRESSEDDOCUMENTHANDLER
+ m_xDocumentHandler->processingInstruction(aTarget, aData);
+ #else
+ m_xCompressedDocumentHandler->_processingInstruction(aTarget, aData);
+ #endif
+ }
+ }
+}
+
+void SAL_CALL SAXEventKeeperImpl::setDocumentLocator( const cssu::Reference< cssxs::XLocator >& xLocator )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+/* XInitialization */
+void SAL_CALL SAXEventKeeperImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ sal_Int32 nLength = aArguments.getLength();
+
+ OSL_ASSERT(nLength == 1);
+
+ aArguments[0] >>= m_xXMLDocument;
+ m_xDocumentHandler = cssu::Reference< cssxs::XDocumentHandler >(
+ m_xXMLDocument, cssu::UNO_QUERY );
+ m_xCompressedDocumentHandler = cssu::Reference< cssxcsax::XCompressedDocumentHandler >(
+ m_xXMLDocument, cssu::UNO_QUERY );
+
+ m_pRootBufferNode = new BufferNode(m_xXMLDocument->getCurrentElement());
+ m_pCurrentBufferNode = m_pRootBufferNode;
+}
+
+rtl::OUString SAXEventKeeperImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL SAXEventKeeperImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL SAXEventKeeperImpl_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 SAXEventKeeperImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new SAXEventKeeperImpl();
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL SAXEventKeeperImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return SAXEventKeeperImpl_getImplementationName();
+}
+sal_Bool SAL_CALL SAXEventKeeperImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return SAXEventKeeperImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL SAXEventKeeperImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return SAXEventKeeperImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/framework/saxeventkeeperimpl.hxx b/xmlsecurity/source/framework/saxeventkeeperimpl.hxx
new file mode 100644
index 000000000000..04ee57e37c50
--- /dev/null
+++ b/xmlsecurity/source/framework/saxeventkeeperimpl.hxx
@@ -0,0 +1,423 @@
+/*************************************************************************
+ *
+ * $RCSfile: saxeventkeeperimpl.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 _SAXEVENTKEEPERIMPL_HXX
+#define _SAXEVENTKEEPERIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSECURITYSAXEVENTKEEPER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSAXEVENTKEEPERSTATUSCHANGEBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSAXEVENTKEEPERSTATUSCHANGELISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CSAX_XCOMPRESSEDDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLDOCUMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/sax/XDocumentHandler.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_IMPLBASE6_HXX_
+#include <cppuhelper/implbase6.hxx>
+#endif
+
+#include "buffernode.hxx"
+#include "elementmark.hxx"
+#include "elementcollector.hxx"
+
+#ifndef INCLUDED_VECTOR
+#include <vector>
+#define INCLUDED_VECTOR
+#endif
+
+class SAXEventKeeperImpl : public cppu::WeakImplHelper6
+<
+ com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper,
+ com::sun::star::xml::crypto::sax::XReferenceResolvedBroadcaster,
+ com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster,
+ com::sun::star::xml::sax::XDocumentHandler,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+>
+/****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
+ *
+ * NAME
+ * SAXEventKeeperImpl -- SAX events buffer controller
+ *
+ * FUNCTION
+ * Controls SAX events to be bufferred, and controls bufferred SAX events
+ * to be released.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XSecuritySAXEventKeeper,
+ * XReferenceResolvedBroadcaster,
+ * XSAXEventKeeperStatusChangeBroadcaster,
+ * XDocumentHandler, XInitialization, XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the XMLDocumentWrapper component which maintains all bufferred SAX
+ * in DOM format.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLDocumentWrapper >
+ m_xXMLDocument;
+
+ /*
+ * the document handler provided by the XMLDocumentWrapper component.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xDocumentHandler;
+
+ /*
+ * the compressed document handler provided by the XMLDocumentWrapper
+ * component, the handler has more effient method definition that the
+ * normal document handler.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::csax::XCompressedDocumentHandler >
+ m_xCompressedDocumentHandler;
+
+ /*
+ * a listener which receives this SAXEventKeeper's status change
+ * notification.
+ * Based on the status changes, the listener can decide whether the
+ * SAXEventKeeper should chain on/chain off the SAX chain, or whether
+ * the SAXEventKeeper is useless any long.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >
+ m_xSAXEventKeeperStatusChangeListener;
+
+ /*
+ * the root node of the BufferNode tree.
+ * the BufferNode tree is used to keep track of all bufferred elements,
+ * it has the same structure with the document which maintains those
+ * elements physically.
+ */
+ BufferNode* m_pRootBufferNode;
+
+ /*
+ * the current active BufferNode.
+ * this is used to keep track the current location in the BufferNode tree,
+ * the next generated BufferNode will become a child BufferNode of it.
+ */
+ BufferNode* m_pCurrentBufferNode;
+
+ /*
+ * the next Id for a coming ElementMark.
+ * the variable is increased by 1 when an new ElementMark is generated,
+ * in this way, we can promise the Id of any ElementMark is unique.
+ */
+ sal_Int32 m_nNextElementMarkId;
+
+ /*
+ * maintains a collection of all ElementMarks.
+ */
+ std::vector< const ElementMark* > m_vElementMarkBuffers;
+
+ /*
+ * maintains a list of new ElementCollectors that will be created
+ * on the element represented by the next incoming startElement SAX
+ * event.
+ * The reason that such the m_vNewElementCollectors is necessary
+ * is: when an ElementCollector is asked to create, it can't be
+ * created completely at once, because the BufferNode it will be
+ * working on has not been created until the next startElement
+ * SAX event comes.
+ */
+ std::vector< const ElementCollector* > m_vNewElementCollectors;
+
+ /*
+ * maintains the new Blocker that will be created
+ * on the element represented by the next incoming startElement SAX
+ * event.
+ */
+ ElementMark* m_pNewBlocker;
+
+ /*
+ * the document handler to which all received SAX events will be
+ * forwarded.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
+
+ /*
+ * the current BufferNode which prevents the SAX events to be
+ * forwarded to the m_xNextHandler.
+ */
+ BufferNode* m_pCurrentBlockingBufferNode;
+
+ /*
+ * maintains a list of ElementMark that has been asked to release.
+ * Because during processing a request of releasing an ElementMark,
+ * another releasing ElementMark request can be invoked. To avoid
+ * reentering the same method, a such request only add that ElementMark
+ * into this ElementMark list, then all ElementMarks will be processed in
+ * order.
+ */
+ std::vector< sal_Int32 > m_vReleasedElementMarkBuffers;
+
+ /*
+ * a flag to indicate whether the ElementMark releasing process is runing.
+ * When a releasing request comes, the assigned ElementMark is added to
+ * the m_vReleasedElementMarkBuffers first, then this flag is checked.
+ * If the ElementMark releasing process is not running, then call that
+ * method.
+ */
+ bool m_bIsReleasing;
+
+ /*
+ * a flag to indicate whether it is the "Forwarding" mode now.
+ * A "Forwarding" mode means that all received SAX events are from the
+ * XMLDocumentWrapper component, instead of up-stream component in the
+ * SAX chain.
+ * The difference between "Forwarding" mode and normal mode is that:
+ * no SAX events need to be transferred to the XMLDocumentWrapper component
+ * again even if a buffer request happens.
+ */
+ bool m_bIsForwarding;
+
+ void setCurrentBufferNode(BufferNode* pBufferNode);
+
+ BufferNode* addNewElementMarkBuffers();
+
+ ElementMark* findElementMarkBuffer(sal_Int32 nId) const;
+
+ void removeElementMarkBuffer(sal_Int32 nId);
+
+ rtl::OUString printBufferNode(
+ BufferNode* pBufferNode, sal_Int32 nIndent) const;
+
+ com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > >
+ collectChildWorkingElement(BufferNode* pBufferNode) const;
+
+ void smashBufferNode(
+ BufferNode* pBufferNode, bool bClearRoot) const;
+
+ BufferNode* findNextBlockingBufferNode(
+ BufferNode* pStartBufferNode) const;
+
+ void diffuse(BufferNode* pBufferNode) const;
+
+ void releaseElementMarkBuffer();
+
+ void markElementMarkBuffer(sal_Int32 nId);
+
+ sal_Int32 createElementCollector(
+ sal_Int32 nSecurityId,
+ com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority,
+ bool bModifyElement,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener>&
+ xReferenceResolvedListener);
+
+ sal_Int32 createBlocker(sal_Int32 nSecurityId);
+
+public:
+ SAXEventKeeperImpl();
+ virtual ~SAXEventKeeperImpl();
+
+ /* XSAXEventKeeper */
+ virtual sal_Int32 SAL_CALL addElementCollector( )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeElementCollector( sal_Int32 id )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual sal_Int32 SAL_CALL addBlocker( )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeBlocker( sal_Int32 id )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL isBlocking( )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
+ getElement( sal_Int32 id )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setElement(
+ sal_Int32 id,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >&
+ aElement )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > SAL_CALL
+ setNextHandler( const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xNewHandler )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual rtl::OUString SAL_CALL printBufferNodeTree()
+ throw (com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
+ getCurrentBlockingNode()
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* XSecuritySAXEventKeeper */
+ virtual sal_Int32 SAL_CALL addSecurityElementCollector(
+ com::sun::star::xml::crypto::sax::ElementMarkPriority priority,
+ sal_Bool modifyElement )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual sal_Int32 SAL_CALL cloneElementCollector(
+ sal_Int32 referenceId,
+ com::sun::star::xml::crypto::sax::ElementMarkPriority priority )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setSecurityId( sal_Int32 id, sal_Int32 securityId )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* XReferenceResolvedBroadcaster */
+ virtual void SAL_CALL addReferenceResolvedListener(
+ sal_Int32 referenceId,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeReferenceResolvedListener(
+ sal_Int32 referenceId,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* XSAXEventKeeperStatusChangeBroadcaster */
+ virtual void SAL_CALL addXSAXEventKeeperStatusChangeListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeXSAXEventKeeperStatusChangeListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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 SAXEventKeeperImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL SAXEventKeeperImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SAXEventKeeperImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL SAXEventKeeperImpl_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/framework/securityengine.cxx b/xmlsecurity/source/framework/securityengine.cxx
new file mode 100644
index 000000000000..d4528b3c25b1
--- /dev/null
+++ b/xmlsecurity/source/framework/securityengine.cxx
@@ -0,0 +1,122 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityengine.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "securityengine.hxx"
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+SecurityEngine::SecurityEngine( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
+ :mxMSF( rxMSF ),
+ m_nIdOfTemplateEC(-1),
+ m_nIdOfKeyEC(-1),
+ m_nNumOfResolvedReferences(0),
+ m_bMissionDone(false),
+ m_nSecurityId(-1),
+ m_bOperationSucceed(false)
+{
+}
+
+/* XReferenceResolvedListener */
+void SAL_CALL SecurityEngine::referenceResolved( sal_Int32 referenceId )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+{
+ m_nNumOfResolvedReferences++;
+ tryToPerform();
+}
+
+/* XKeyCollector */
+void SAL_CALL SecurityEngine::setKeyId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+{
+ m_nIdOfKeyEC = id;
+ tryToPerform();
+}
+
+/* XMissionTaker */
+sal_Bool SAL_CALL SecurityEngine::endMission( )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ sal_Bool rc = m_bMissionDone;
+
+ if (!rc)
+ {
+ clearUp( );
+
+ notifyResultListener();
+ m_bMissionDone = true;
+ }
+
+ m_xResultListener = NULL;
+ m_xSAXEventKeeper = NULL;
+
+ return rc;
+}
+
diff --git a/xmlsecurity/source/framework/securityengine.hxx b/xmlsecurity/source/framework/securityengine.hxx
new file mode 100644
index 000000000000..e944f6b42554
--- /dev/null
+++ b/xmlsecurity/source/framework/securityengine.hxx
@@ -0,0 +1,225 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityengine.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _SECURITYENGINE_HXX
+#define _SECURITYENGINE_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XKEYCOLLECTOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XMISSIONTAKER_HPP_
+#include <com/sun/star/xml/crypto/sax/XMissionTaker.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_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignature.hpp>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE3_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+class SecurityEngine : public cppu::WeakImplHelper3
+<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener,
+ com::sun::star::xml::crypto::sax::XKeyCollector,
+ com::sun::star::xml::crypto::sax::XMissionTaker
+>
+/****** securityengine.hxx/CLASS SecurityEngine *******************************
+ *
+ * NAME
+ * SecurityEngine -- Base class of SignatureEngine and EncryptionEngine
+ *
+ * FUNCTION
+ * Maintains common members and methods related with security engine
+ * operation.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XReferenceResolvedListener,
+ * XKeyCollector, and XMissionTaker
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+protected:
+ com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory > mxMSF;
+
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSecurityContext > m_xXMLSecurityContext;
+
+ /*
+ * A SAXEventKeeper internally maintians all resources that a security
+ * operation needs. The m_xSAXEventKeeper member is used to release
+ * those resources when the security operation finishes.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSAXEventKeeper > m_xSAXEventKeeper;
+
+ /*
+ * the id of ElementCollector of the template element.
+ * For a signature, the template element is the Signature element,
+ * for a encryption, the EncryptedData/EncryptedKey element is.
+ */
+ sal_Int32 m_nIdOfTemplateEC;
+
+ /*
+ * remembers how many referenced elements have been bufferred completely,
+ * including the key element, template element, and referenced element of
+ * signature.
+ */
+ sal_Int32 m_nNumOfResolvedReferences;
+
+ /*
+ * the id of ElementCollector of the key element.
+ * If a Signature element or EncryptedData/EncryptedKey element has
+ * an internal key sub-element, then this member should be -1
+ */
+ sal_Int32 m_nIdOfKeyEC;
+
+ /*
+ * remembers whether the current opertion has finished.
+ */
+ bool m_bMissionDone;
+
+ /*
+ * the Id of the security entity, a signature or encryption, which is used for
+ * the result listener to identify the entity.
+ */
+ sal_Int32 m_nSecurityId;
+
+ /*
+ * the result of the operation
+ */
+ bool m_bOperationSucceed;
+
+ /*
+ * the result listener, which will receives the security operation result.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::uno::XInterface >
+ m_xResultListener;
+
+protected:
+ explicit SecurityEngine( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory >& rxMSF = NULL );
+ virtual ~SecurityEngine() {};
+
+ /*
+ * perform the security operation.
+ * Any derived class will implement this method respectively.
+ */
+ virtual void tryToPerform( )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException){};
+
+ /*
+ * clear up all resources used by this operation.
+ * This method is called after the operation finishes, or a End-Your-Mission
+ * message is received.
+ * Any derived class will implement this method respectively.
+ */
+ virtual void clearUp( ) const {};
+
+ /*
+ * notifies any possible result listener.
+ * When verify a signature or conduct a decryption, the operation result will
+ * be transferred to a listener by this method.
+ * Any derived class will implement this method respectively.
+ */
+ virtual void notifyResultListener() const
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+ {};
+
+ /*
+ * checks whether everything is ready.
+ * Any derived class will implement this method respectively.
+ */
+ virtual bool checkReady() const { return true; };
+
+public:
+ /* XReferenceResolvedListener */
+ virtual void SAL_CALL referenceResolved( sal_Int32 referenceId )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ /* XKeyCollector */
+ virtual void SAL_CALL setKeyId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ /* XMissionTaker */
+ virtual sal_Bool SAL_CALL endMission( )
+ throw (com::sun::star::uno::RuntimeException);
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/signaturecreatorimpl.cxx b/xmlsecurity/source/framework/signaturecreatorimpl.cxx
new file mode 100644
index 000000000000..3de42e6c4e11
--- /dev/null
+++ b/xmlsecurity/source/framework/signaturecreatorimpl.cxx
@@ -0,0 +1,343 @@
+/*************************************************************************
+ *
+ * $RCSfile: signaturecreatorimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "signaturecreatorimpl.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURETEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_SIGNATURECREATIONRESULT_HPP_
+#include <com/sun/star/xml/crypto/sax/SignatureCreationResult.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureCreator"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+SignatureCreatorImpl::SignatureCreatorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
+ :m_nIdOfBlocker(-1)
+{
+ mxMSF = rxMSF;
+}
+
+SignatureCreatorImpl::~SignatureCreatorImpl( )
+{
+}
+
+bool SignatureCreatorImpl::checkReady() const
+/****** SignatureCreatorImpl/checkReady **************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the signature generation.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the result listener is ready;
+ * 2. the id of the template blocker is known;
+ * 3. the SignatureEngine is ready.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return (m_xResultListener.is() &&
+ (m_nIdOfBlocker != -1) &&
+ SignatureEngine::checkReady());
+}
+
+void SignatureCreatorImpl::notifyResultListener() const
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** SignatureCreatorImpl/notifyResultListener *****************************
+ *
+ * NAME
+ * notifyResultListener -- notifies the listener about the signature
+ * creation result.
+ *
+ * SYNOPSIS
+ * notifyResultListener( );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
+ xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
+
+ xSignatureCreationResultListener->signatureCreated(
+ m_nSecurityId,
+ m_bOperationSucceed?(cssxc::sax::SignatureCreationResult_CREATIONSUCCEED):
+ (cssxc::sax::SignatureCreationResult_CREATIONFAIL));
+}
+
+void SignatureCreatorImpl::startEngine( const cssu::Reference<
+ cssxc::XXMLSignatureTemplate >&
+ xSignatureTemplate)
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** SignatureCreatorImpl/startEngine *************************************
+ *
+ * NAME
+ * startEngine -- generates the signature.
+ *
+ * SYNOPSIS
+ * startEngine( xSignatureTemplate );
+ *
+ * FUNCTION
+ * generates the signature element, then if succeeds, updates the link
+ * of old template element to the new signature element in
+ * SAXEventKeeper.
+ *
+ * INPUTS
+ * xSignatureTemplate - the signature template (along with all referenced
+ * elements) to be signed.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
+ try
+ {
+ xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xXMLSecurityContext);
+ }
+ catch( cssu::Exception& )
+ {
+ xResultTemplate = NULL;
+ }
+
+ if (xResultTemplate.is())
+ {
+ cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
+ m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
+
+ m_bOperationSucceed = true;
+ }
+}
+
+void SignatureCreatorImpl::clearUp() const
+/****** SignatureCreatorImpl/clearUp *****************************************
+ *
+ * NAME
+ * clearUp -- clear up all resources used by the signature generation.
+ *
+ * SYNOPSIS
+ * clearUp( );
+ *
+ * FUNCTION
+ * cleaning resources up includes:
+ * 1. SignatureEngine's clearing up;
+ * 2. releases the Blocker for the signature template element.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ SignatureEngine::clearUp();
+
+ if (m_nIdOfBlocker != -1)
+ {
+ m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
+ }
+}
+
+/* XBlockerMonitor */
+void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_nIdOfBlocker = id;
+ tryToPerform();
+}
+
+/* XSignatureCreationResultBroadcaster */
+void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_xResultListener = listener;
+ tryToPerform();
+}
+
+void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XInitialization */
+void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ sal_Int32 nLength = aArguments.getLength();
+ OSL_ASSERT(nLength == 5);
+
+ rtl::OUString ouTempString;
+
+ aArguments[0] >>= ouTempString;
+ m_nSecurityId = ouTempString.toInt32();
+ aArguments[1] >>= m_xSAXEventKeeper;
+ aArguments[2] >>= ouTempString;
+ m_nIdOfTemplateEC = ouTempString.toInt32();
+ aArguments[3] >>= m_xXMLSecurityContext;
+ aArguments[4] >>= m_xXMLSignature;
+}
+
+
+rtl::OUString SignatureCreatorImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_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 SignatureCreatorImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new SignatureCreatorImpl( rSMgr );
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return SignatureCreatorImpl_getImplementationName();
+}
+sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return SignatureCreatorImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return SignatureCreatorImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/framework/signaturecreatorimpl.hxx b/xmlsecurity/source/framework/signaturecreatorimpl.hxx
new file mode 100644
index 000000000000..e2ef6f7f1e2e
--- /dev/null
+++ b/xmlsecurity/source/framework/signaturecreatorimpl.hxx
@@ -0,0 +1,189 @@
+/*************************************************************************
+ *
+ * $RCSfile: signaturecreatorimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _SIGNATURECREATORIMPL_HXX
+#define _SIGNATURECREATORIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XBLOCKERMONITOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XBlockerMonitor.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATURECREATIONRESULTLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSignatureCreationResultListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATURECREATIONRESULTBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSignatureCreationResultBroadcaster.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_IMPLBASE4_HXX_
+#include <cppuhelper/implbase4.hxx>
+#endif
+
+#include "signatureengine.hxx"
+
+class SignatureCreatorImpl : public cppu::ImplInheritanceHelper4
+<
+ SignatureEngine,
+ com::sun::star::xml::crypto::sax::XBlockerMonitor,
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultBroadcaster,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+>
+/****** SignatureCreatorImpl.hxx/CLASS SignatureCreatorImpl *******************
+ *
+ * NAME
+ * SignatureCreatorImpl -- generates a signature
+ *
+ * FUNCTION
+ * Collects all resources for a signature generation, then generates the
+ * signature by invoking a xmlsec-based signature bridge component.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XBlockerMonitor,
+ * XInitialization, XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the Id of the signature, which is used for the result listener to
+ * identify the signature.
+ */
+ sal_Int32 m_nSignatureId;
+
+ /*
+ * the Id of template blocker.
+ */
+ sal_Int32 m_nIdOfBlocker;
+
+ /*
+ * the signature creation result
+ */
+ bool m_bCreationSucceed;
+
+ virtual void notifyResultListener() const
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void clearUp( ) const;
+ virtual bool checkReady() const;
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSignatureTemplate >&
+ xSignatureTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+public:
+ explicit SignatureCreatorImpl( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory >& rxMSF);
+ virtual ~SignatureCreatorImpl();
+
+ /* XBlockerMonitor */
+ virtual void SAL_CALL setBlockerId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ /* XSignatureCreationResultBroadcaster */
+ void SAL_CALL addSignatureCreationResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener >& listener )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL removeSignatureCreationResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener >& listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* 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);
+
+ /* 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 SignatureCreatorImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL SignatureCreatorImpl_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/framework/signatureengine.cxx b/xmlsecurity/source/framework/signatureengine.cxx
new file mode 100644
index 000000000000..bbb3765cf4e6
--- /dev/null
+++ b/xmlsecurity/source/framework/signatureengine.cxx
@@ -0,0 +1,306 @@
+/*************************************************************************
+ *
+ * $RCSfile: signatureengine.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "signatureengine.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURETEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SIGNATURE_TEMPLATE "com.sun.star.xml.crypto.XMLSignatureTemplate"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+SignatureEngine::SignatureEngine( )
+ :m_nTotalReferenceNumber(-1)
+{
+}
+
+bool SignatureEngine::checkReady() const
+/****** SignatureEngine/checkReady *******************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the main operation.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the main operation has't begun yet;
+ * 2. the key material is known;
+ * 3. the amount of reference is known;
+ * 4. all of referenced elements, the key element and the signature
+ * template are bufferred.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = true;
+
+ sal_Int32 nKeyInc = 0;
+ if (m_nIdOfKeyEC != 0)
+ {
+ nKeyInc = 1;
+ }
+
+ if (m_bMissionDone ||
+ m_nIdOfKeyEC == -1 ||
+ m_nTotalReferenceNumber == -1 ||
+ m_nTotalReferenceNumber+1+nKeyInc > m_nNumOfResolvedReferences)
+ {
+ rc = false;
+ }
+
+ return rc;
+}
+
+void SignatureEngine::tryToPerform( )
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** SignatureEngine/tryToPerform *****************************************
+ *
+ * NAME
+ * tryToPerform -- tries to perform the signature operation.
+ *
+ * SYNOPSIS
+ * tryToPerform( );
+ *
+ * FUNCTION
+ * if the situation is ready, perform following operations.
+ * 1. prepares a signature template;
+ * 2. calls the signature bridge component;
+ * 3. clears up all used resources;
+ * 4. notifies the result listener;
+ * 5. sets the "accomplishment" flag.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (checkReady())
+ {
+ const rtl::OUString ouSignatureTemplate (
+ RTL_CONSTASCII_USTRINGPARAM( SIGNATURE_TEMPLATE ) );
+ cssu::Reference < cssxc::XXMLSignatureTemplate >
+ xSignatureTemplate( mxMSF->createInstance( ouSignatureTemplate ), cssu::UNO_QUERY );
+
+ OSL_ASSERT( xSignatureTemplate.is() );
+
+ cssu::Reference< cssxw::XXMLElementWrapper >
+ xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC );
+
+ xSignatureTemplate->setTemplate(xXMLElement);
+
+ std::vector< sal_Int32 >::const_iterator ii = m_vReferenceIds.begin();
+
+ for( ; ii != m_vReferenceIds.end() ; ++ii )
+ {
+ xXMLElement = m_xSAXEventKeeper->getElement( *ii );
+ xSignatureTemplate->setTarget(xXMLElement);
+ }
+
+ /*
+ * set the Uri binding
+ */
+ xSignatureTemplate->setBinding( this );
+
+ startEngine( xSignatureTemplate );
+
+ /*
+ * done
+ */
+ clearUp( );
+
+ notifyResultListener();
+
+ m_bMissionDone = true;
+ }
+}
+
+void SignatureEngine::clearUp( ) const
+/****** SignatureEngine/clearUp **********************************************
+ *
+ * NAME
+ * clearUp -- clear up all resources used by this operation.
+ *
+ * SYNOPSIS
+ * clearUp( );
+ *
+ * FUNCTION
+ * cleaning resources up includes:
+ * 1. releases the ElementCollector for the signature template element;
+ * 2. releases ElementCollectors for referenced elements;
+ * 3. releases the ElementCollector for the key element, if there is one.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference < cssxc::sax::XReferenceResolvedBroadcaster >
+ xReferenceResolvedBroadcaster( m_xSAXEventKeeper, cssu::UNO_QUERY );
+ xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
+ m_nIdOfTemplateEC,
+ (const cssu::Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
+
+ m_xSAXEventKeeper->removeElementCollector(m_nIdOfTemplateEC);
+
+ std::vector< sal_Int32 >::const_iterator ii = m_vReferenceIds.begin();
+
+ for( ; ii != m_vReferenceIds.end() ; ++ii )
+ {
+ xReferenceResolvedBroadcaster->removeReferenceResolvedListener(
+ *ii,
+ (const cssu::Reference < cssxc::sax::XReferenceResolvedListener >)((SecurityEngine *)this));
+ m_xSAXEventKeeper->removeElementCollector(*ii);
+ }
+
+ if (m_nIdOfKeyEC != 0 && m_nIdOfKeyEC != -1)
+ {
+ m_xSAXEventKeeper->removeElementCollector(m_nIdOfKeyEC);
+ }
+}
+
+/* XReferenceCollector */
+void SAL_CALL SignatureEngine::setReferenceCount( sal_Int32 count )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_nTotalReferenceNumber = count;
+ tryToPerform();
+}
+
+void SAL_CALL SignatureEngine::setReferenceId( sal_Int32 id )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_vReferenceIds.push_back( id );
+}
+
+/* XUriBinding */
+void SAL_CALL SignatureEngine::setUriBinding(
+ const rtl::OUString& uri,
+ const cssu::Reference< com::sun::star::io::XInputStream >& aInputStream )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_vUris.push_back(uri);
+ m_vXInputStreams.push_back(aInputStream);
+}
+
+cssu::Reference< com::sun::star::io::XInputStream > SAL_CALL SignatureEngine::getUriBinding( const rtl::OUString& uri )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ cssu::Reference< com::sun::star::io::XInputStream > xInputStream;
+
+ int size = m_vUris.size();
+
+ for( int i=0; i<size; ++i)
+ {
+ if (m_vUris[i] == uri)
+ {
+ xInputStream = m_vXInputStreams[i];
+ break;
+ }
+ }
+
+ return xInputStream;
+}
+
diff --git a/xmlsecurity/source/framework/signatureengine.hxx b/xmlsecurity/source/framework/signatureengine.hxx
new file mode 100644
index 000000000000..e349faec6a9a
--- /dev/null
+++ b/xmlsecurity/source/framework/signatureengine.hxx
@@ -0,0 +1,199 @@
+/*************************************************************************
+ *
+ * $RCSfile: signatureengine.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _SIGNATUREENGINE_HXX
+#define _SIGNATUREENGINE_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XREFERENCERESOLVEDBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATURECOLLECTOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XKEYCOLLECTOR_HPP_
+#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XMISSIONTAKER_HPP_
+#include <com/sun/star/xml/crypto/sax/XMissionTaker.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_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.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_XURIBINDING_HPP_
+#include <com/sun/star/xml/crypto/XUriBinding.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
+#include <com/sun/star/io/XInputStream.hpp>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE2_HXX_
+#include <cppuhelper/implbase2.hxx>
+#endif
+
+#include "securityengine.hxx"
+
+#ifndef INCLUDED_VECTOR
+#include <vector>
+#define INCLUDED_VECTOR
+#endif
+
+class SignatureEngine : public cppu::ImplInheritanceHelper2
+<
+ SecurityEngine,
+ com::sun::star::xml::crypto::sax::XReferenceCollector,
+ com::sun::star::xml::crypto::XUriBinding
+>
+/****** signatureengine.hxx/CLASS SignatureEngine *****************************
+ *
+ * NAME
+ * SignatureEngine -- Base class of SignatureCreator and SignatureVerifier
+ *
+ * FUNCTION
+ * Maintains common members and methods related with signature operation.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XReferenceCollector
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+protected:
+
+ /*
+ * the Signature bridge component, which performs signature generation
+ * and verification based on xmlsec library.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSignature > m_xXMLSignature;
+
+ /*
+ * a collection of ElementCollector's ids. Each ElementCollector
+ * represents one element signed by this signature.
+ */
+ std::vector< sal_Int32 > m_vReferenceIds;
+
+ /*
+ * remembers how many references this signature has.
+ */
+ sal_Int32 m_nTotalReferenceNumber;
+
+ /*
+ * a collection of Uri binding.
+ *
+ * the m_vUris is used to hold the Uri strings, and the m_vXInputStreams is used
+ * to hold corresponding binded XInputStream interface.
+ */
+ std::vector< rtl::OUString > m_vUris;
+ std::vector< com::sun::star::uno::Reference<
+ com::sun::star::io::XInputStream > > m_vXInputStreams;
+
+protected:
+ SignatureEngine( );
+ virtual ~SignatureEngine() {};
+
+ virtual void tryToPerform( )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void clearUp( ) const;
+ virtual bool checkReady() const;
+
+ /*
+ * starts the main function. This method will be implemented by any sub-class.
+ * For a SignatureCreator, it performs signing operation;
+ * for a SignatureVerifier, verification operation is performed.
+ */
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSignatureTemplate >&
+ xSignatureTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
+ {};
+
+public:
+ /* XReferenceCollector */
+ virtual void SAL_CALL setReferenceCount( sal_Int32 count )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setReferenceId( sal_Int32 id )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+ /* XUriBinding */
+ virtual void SAL_CALL setUriBinding(
+ const rtl::OUString& uri,
+ const com::sun::star::uno::Reference<
+ com::sun::star::io::XInputStream >& aInputStream )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
+ SAL_CALL getUriBinding( const rtl::OUString& uri )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+};
+
+#endif
+
diff --git a/xmlsecurity/source/framework/signatureverifierimpl.cxx b/xmlsecurity/source/framework/signatureverifierimpl.cxx
new file mode 100644
index 000000000000..e6e8a084ab4b
--- /dev/null
+++ b/xmlsecurity/source/framework/signatureverifierimpl.cxx
@@ -0,0 +1,288 @@
+/*************************************************************************
+ *
+ * $RCSfile: signatureverifierimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 "signatureverifierimpl.hxx"
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURETEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_SIGNATUREVERIFYRESULT_HPP_
+#include <com/sun/star/xml/crypto/sax/SignatureVerifyResult.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
+
+#define DECLARE_ASCII( SASCIIVALUE ) \
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
+
+SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
+{
+ mxMSF = rxMSF;
+}
+
+SignatureVerifierImpl::~SignatureVerifierImpl()
+{
+}
+
+bool SignatureVerifierImpl::checkReady() const
+/****** SignatureVerifierImpl/checkReady *************************************
+ *
+ * NAME
+ * checkReady -- checks the conditions for the signature verification.
+ *
+ * SYNOPSIS
+ * bReady = checkReady( );
+ *
+ * FUNCTION
+ * checks whether all following conditions are satisfied:
+ * 1. the result listener is ready;
+ * 2. the SignatureEngine is ready.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * bReady - true if all conditions are satisfied, false otherwise
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return (m_xResultListener.is() && SignatureEngine::checkReady());
+}
+
+void SignatureVerifierImpl::notifyResultListener() const
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** SignatureVerifierImpl/notifyResultListener ***************************
+ *
+ * NAME
+ * notifyResultListener -- notifies the listener about the verify result.
+ *
+ * SYNOPSIS
+ * notifyResultListener( );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >
+ xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
+
+ xSignatureVerifyResultListener->signatureVerified(
+ m_nSecurityId,
+ m_bOperationSucceed?(cssxc::sax::SignatureVerifyResult_VERIFYSUCCEED):
+ (cssxc::sax::SignatureVerifyResult_VERIFYFAIL));
+}
+
+void SignatureVerifierImpl::startEngine( const cssu::Reference<
+ cssxc::XXMLSignatureTemplate >&
+ xSignatureTemplate)
+ throw (cssu::Exception, cssu::RuntimeException)
+/****** SignatureVerifierImpl/startEngine ************************************
+ *
+ * NAME
+ * startEngine -- verifies the signature.
+ *
+ * SYNOPSIS
+ * startEngine( xSignatureTemplate );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * xSignatureTemplate - the signature template (along with all referenced
+ * elements) to be verified.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ try
+ {
+ if ( m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext))
+ {
+ m_bOperationSucceed = true;
+ }
+ }
+ catch( cssu::Exception& )
+ {
+ m_bOperationSucceed = false;
+ }
+}
+
+/* XSignatureVerifyResultBroadcaster */
+void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ m_xResultListener = listener;
+ tryToPerform();
+}
+
+void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
+ throw (cssu::RuntimeException)
+{
+}
+
+/* XInitialization */
+void SAL_CALL SignatureVerifierImpl::initialize(
+ const cssu::Sequence< cssu::Any >& aArguments )
+ throw (cssu::Exception, cssu::RuntimeException)
+{
+ sal_Int32 nLength = aArguments.getLength();
+ OSL_ASSERT(nLength == 5);
+
+ rtl::OUString ouTempString;
+
+ aArguments[0] >>= ouTempString;
+ m_nSecurityId = ouTempString.toInt32();
+ aArguments[1] >>= m_xSAXEventKeeper;
+ aArguments[2] >>= ouTempString;
+ m_nIdOfTemplateEC = ouTempString.toInt32();
+ aArguments[3] >>= m_xXMLSecurityContext;
+ aArguments[4] >>= m_xXMLSignature;
+}
+
+
+rtl::OUString SignatureVerifierImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL SignatureVerifierImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl_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 SignatureVerifierImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new SignatureVerifierImpl(rSMgr);
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL SignatureVerifierImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return SignatureVerifierImpl_getImplementationName();
+}
+sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return SignatureVerifierImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return SignatureVerifierImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/framework/signatureverifierimpl.hxx b/xmlsecurity/source/framework/signatureverifierimpl.hxx
new file mode 100644
index 000000000000..74ad65ccab05
--- /dev/null
+++ b/xmlsecurity/source/framework/signatureverifierimpl.hxx
@@ -0,0 +1,175 @@
+/*************************************************************************
+ *
+ * $RCSfile: signatureverifierimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _SIGNATUREVERIFIERIMPL_HXX
+#define _SIGNATUREVERIFIERIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATUREVERIFYRESULTLISTENER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATUREVERIFYRESULTBROADCASTER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.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 "signatureengine.hxx"
+
+class SignatureVerifierImpl : public cppu::ImplInheritanceHelper3
+<
+ SignatureEngine,
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultBroadcaster,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+>
+/****** SignatureVerifier.hxx/CLASS SignatureVerifierImpl *********************
+ *
+ * NAME
+ * SignatureVerifierImpl -- verifies a signature
+ *
+ * FUNCTION
+ * Collects all resources for a signature verification, then verifies the
+ * signature by invoking a xmlsec-based signature bridge component.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XSignatureVerifyResultBroadcaster,
+ * XInitialization, XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /*
+ * the Id of the signature, which is used for the result listener to
+ * identify the signature.
+ */
+ sal_Int32 m_nSignatureId;
+
+ /*
+ * the verify result
+ */
+ bool m_bVerifySucceed;
+
+ virtual void notifyResultListener() const
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual bool checkReady() const;
+ virtual void startEngine( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSignatureTemplate >&
+ xSignatureTemplate)
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+
+public:
+ explicit SignatureVerifierImpl( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory >& rxMSF);
+ virtual ~SignatureVerifierImpl();
+
+ /* XSignatureVerifyResultBroadcaster */
+ virtual void SAL_CALL addSignatureVerifyResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener >&
+ listener )
+ throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeSignatureVerifyResultListener(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener >&
+ listener )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* 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);
+
+ /* 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 SignatureVerifierImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL SignatureVerifierImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL SignatureVerifierImpl_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/framework/xmlencryptiontemplateimpl.cxx b/xmlsecurity/source/framework/xmlencryptiontemplateimpl.cxx
new file mode 100644
index 000000000000..b32f11caeeb8
--- /dev/null
+++ b/xmlsecurity/source/framework/xmlencryptiontemplateimpl.cxx
@@ -0,0 +1,164 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryptiontemplateimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _XMLENCRYPTIONTEMPLATEIMPL_HXX_
+#include "xmlencryptiontemplateimpl.hxx"
+#endif
+
+using namespace ::com::sun::star::uno ;
+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::crypto::XXMLEncryptionTemplate ;
+
+XMLEncryptionTemplateImpl :: XMLEncryptionTemplateImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) , m_xTemplate( NULL ) , m_xTarget( NULL ) {
+}
+
+XMLEncryptionTemplateImpl :: ~XMLEncryptionTemplateImpl() {
+}
+
+/* XXMLEncryptionTemplate */
+void SAL_CALL XMLEncryptionTemplateImpl :: setTemplate( const Reference< XXMLElementWrapper >& aTemplate )
+ throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
+{
+ m_xTemplate = aTemplate ;
+}
+
+/* XXMLEncryptionTemplate */
+Reference< XXMLElementWrapper > SAL_CALL XMLEncryptionTemplateImpl :: getTemplate()
+throw (com::sun::star::uno::RuntimeException)
+{
+ return m_xTemplate ;
+}
+
+/* XXMLEncryptionTemplate */
+void SAL_CALL XMLEncryptionTemplateImpl :: setTarget( const Reference< XXMLElementWrapper >& aTarget )
+ throw( com::sun::star::lang::IllegalArgumentException ) {
+ m_xTarget = aTarget ;
+}
+
+/* XXMLEncryptionTemplate */
+Reference< XXMLElementWrapper > SAL_CALL XMLEncryptionTemplateImpl :: getTarget()
+throw (com::sun::star::uno::RuntimeException)
+{
+ return m_xTarget ;
+}
+
+/* XInitialization */
+void SAL_CALL XMLEncryptionTemplateImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLEncryptionTemplateImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLEncryptionTemplateImpl :: 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 XMLEncryptionTemplateImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLEncryptionTemplateImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLEncryptionTemplate" ) ;
+ return seqServiceNames ;
+}
+
+OUString XMLEncryptionTemplateImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.framework.XMLEncryptionTemplateImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLEncryptionTemplateImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLEncryptionTemplateImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLEncryptionTemplateImpl :: 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/framework/xmlencryptiontemplateimpl.hxx b/xmlsecurity/source/framework/xmlencryptiontemplateimpl.hxx
new file mode 100644
index 000000000000..e020aacd8ae5
--- /dev/null
+++ b/xmlsecurity/source/framework/xmlencryptiontemplateimpl.hxx
@@ -0,0 +1,168 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryptiontemplateimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _XMLENCRYPTIONTEMPLATEIMPL_HXX_
+#define _XMLENCRYPTIONTEMPLATEIMPL_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_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+
+class XMLEncryptionTemplateImpl : public ::cppu::WeakImplHelper3<
+ ::com::sun::star::xml::crypto::XXMLEncryptionTemplate ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ private :
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > m_xTemplate ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > m_xTarget ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ XMLEncryptionTemplateImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLEncryptionTemplateImpl() ;
+
+ //Methods from XXMLEncryptionTemplate
+ virtual void SAL_CALL setTemplate(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement
+ )
+ throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException);
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getTemplate(
+ ) throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setTarget(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement
+ ) throw( com::sun::star::lang::IllegalArgumentException);
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getTarget(
+ ) 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 ) ;
+} ;
+
+#endif // _XMLENCRYPTIONTEMPLATE_XMLSECIMPL_HXX_
diff --git a/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx
new file mode 100644
index 000000000000..48a27f5db9c2
--- /dev/null
+++ b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx
@@ -0,0 +1,193 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignaturetemplateimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#ifndef _XMLSIGNATURETEMPLATEIMPL_HXX_
+#include "xmlsignaturetemplateimpl.hxx"
+#endif
+
+using namespace ::com::sun::star::uno ;
+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::crypto::XXMLSignatureTemplate ;
+
+XMLSignatureTemplateImpl :: XMLSignatureTemplateImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) , m_xTemplate( NULL ) {
+}
+
+XMLSignatureTemplateImpl :: ~XMLSignatureTemplateImpl() {
+}
+
+/* XXMLSignatureTemplate */
+void SAL_CALL XMLSignatureTemplateImpl :: setTemplate( const Reference< XXMLElementWrapper >& aTemplate )
+ throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
+{
+ m_xTemplate = aTemplate ;
+}
+
+/* XXMLSignatureTemplate */
+Reference< XXMLElementWrapper > SAL_CALL XMLSignatureTemplateImpl :: getTemplate()
+ throw (com::sun::star::uno::RuntimeException)
+{
+ return m_xTemplate ;
+}
+
+void SAL_CALL XMLSignatureTemplateImpl :: setTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement )
+ throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
+{
+ targets.push_back( aXmlElement );
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > > SAL_CALL XMLSignatureTemplateImpl :: getTargets()
+ throw (com::sun::star::uno::RuntimeException)
+{
+ sal_Int32 length = targets.size();
+ ::com::sun::star::uno::Sequence<
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >
+ > aTargets (length);
+
+ sal_Int32 i;
+
+ for (i=0; i<length; i++)
+ {
+ aTargets[i] = targets[i];
+ }
+
+ return aTargets;
+}
+
+void SAL_CALL XMLSignatureTemplateImpl::setBinding(
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::crypto::XUriBinding >& aUriBinding )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
+{
+ m_xUriBinding = aUriBinding;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding > SAL_CALL XMLSignatureTemplateImpl::getBinding()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ return m_xUriBinding;
+}
+
+/* XInitialization */
+void SAL_CALL XMLSignatureTemplateImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLSignatureTemplateImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSignatureTemplateImpl :: 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 XMLSignatureTemplateImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLSignatureTemplateImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSignatureTemplate" ) ;
+ return seqServiceNames ;
+}
+
+OUString XMLSignatureTemplateImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.framework.XMLSignatureTemplateImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLSignatureTemplateImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLSignatureTemplateImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLSignatureTemplateImpl :: 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/framework/xmlsignaturetemplateimpl.hxx b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.hxx
new file mode 100644
index 000000000000..e4368b5656ca
--- /dev/null
+++ b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.hxx
@@ -0,0 +1,177 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignaturetemplateimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 _XMLSIGNATURETEMPLATEIMPL_HXX_
+#define _XMLSIGNATURETEMPLATEIMPL_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_XXMLSIGNATURETEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+
+#ifndef __SGI_STL_VECTOR
+#include <vector>
+#endif
+
+class XMLSignatureTemplateImpl : public ::cppu::WeakImplHelper3<
+ ::com::sun::star::xml::crypto::XXMLSignatureTemplate ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ private :
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > m_xTemplate ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+ std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > > targets;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding > m_xUriBinding;
+
+ public :
+ XMLSignatureTemplateImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLSignatureTemplateImpl() ;
+
+ //Methods from XXMLSignatureTemplate
+ virtual void SAL_CALL setTemplate(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement
+ ) throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException);
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getTemplate(
+ ) throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setTarget(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement
+ ) throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException);
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > > SAL_CALL getTargets(
+ ) throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setBinding(
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::crypto::XUriBinding >& aUriBinding )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::crypto::XUriBinding >
+ SAL_CALL getBinding( )
+ 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 ) ;
+} ;
+
+#endif // _XMLSIGNATURETEMPLATE_XMLSECIMPL_HXX_
diff --git a/xmlsecurity/source/framework/xsec_framework.cxx b/xmlsecurity/source/framework/xsec_framework.cxx
new file mode 100644
index 000000000000..d38ef486f49b
--- /dev/null
+++ b/xmlsecurity/source/framework/xsec_framework.cxx
@@ -0,0 +1,284 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsec_framework.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:23 $
+ *
+ * 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 <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 <decryptorimpl.hxx>
+#include <encryptorimpl.hxx>
+#include <signaturecreatorimpl.hxx>
+#include <signatureverifierimpl.hxx>
+#include <saxeventkeeperimpl.hxx>
+#include <xmlencryptiontemplateimpl.hxx>
+#include <xmlsignaturetemplateimpl.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"
+{
+//==================================================================================================
+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 )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ //Decryptor
+ sal_Int32 nPos = 0;
+ Reference< XRegistryKey > xNewKey(
+ reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( DecryptorImpl_getImplementationName() ) );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+ const Sequence< OUString > & rSNL = DecryptorImpl_getSupportedServiceNames();
+ const OUString * pArray = rSNL.getConstArray();
+ for ( nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ //Encryptor
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( EncryptorImpl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL2 = EncryptorImpl_getSupportedServiceNames();
+ pArray = rSNL2.getConstArray();
+ for ( nPos = rSNL2.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ //SignatureCreator
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SignatureCreatorImpl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL3 = SignatureCreatorImpl_getSupportedServiceNames();
+ pArray = rSNL3.getConstArray();
+ for ( nPos = rSNL3.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ //SignatureVerifier
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SignatureVerifierImpl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL4 = SignatureVerifierImpl_getSupportedServiceNames();
+ pArray = rSNL4.getConstArray();
+ for ( nPos = rSNL4.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ //SAXEventKeeper
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( SAXEventKeeperImpl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL5 = SAXEventKeeperImpl_getSupportedServiceNames();
+ pArray = rSNL5.getConstArray();
+ for ( nPos = rSNL5.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ //XMLSignatureTemplateImpl
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( XMLSignatureTemplateImpl::impl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL6 = XMLSignatureTemplateImpl::impl_getSupportedServiceNames();
+ pArray = rSNL6.getConstArray();
+ for ( nPos = rSNL6.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ // XMLEncryptionTemplateImpl
+ xNewKey = reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( XMLEncryptionTemplateImpl::impl_getImplementationName() );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+ const Sequence< OUString > & rSNL7 = XMLEncryptionTemplateImpl::impl_getSupportedServiceNames();
+ pArray = rSNL7.getConstArray();
+ for ( nPos = rSNL7.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+//==================================================================================================
+void * SAL_CALL component_getFactory(
+ const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void * pRet = 0;
+
+ //Decryptor
+ OUString implName = OUString::createFromAscii( pImplName );
+ if ( pServiceManager && implName.equals(DecryptorImpl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ DecryptorImpl_createInstance, DecryptorImpl_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //Encryptor
+ if ( pServiceManager && implName.equals(EncryptorImpl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ EncryptorImpl_createInstance, EncryptorImpl_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //SignatureCreator
+ if ( pServiceManager && implName.equals(SignatureCreatorImpl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ SignatureCreatorImpl_createInstance, SignatureCreatorImpl_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //SignatureVerifier
+ if ( pServiceManager && implName.equals(SignatureVerifierImpl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ SignatureVerifierImpl_createInstance, SignatureVerifierImpl_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //SAXEventKeeper
+ if ( pServiceManager && implName.equals(SAXEventKeeperImpl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ SAXEventKeeperImpl_createInstance, SAXEventKeeperImpl_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //XMLSignatureTemplate
+ if ( pServiceManager && implName.equals( XMLSignatureTemplateImpl::impl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory = XMLSignatureTemplateImpl::impl_createFactory(
+ reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ //XMLEncryptionTemplate
+ if ( pServiceManager && implName.equals( XMLEncryptionTemplateImpl::impl_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory = XMLEncryptionTemplateImpl::impl_createFactory(
+ reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+
+ return pRet;
+}
+}
+
+
diff --git a/xmlsecurity/source/helper/makefile.mk b/xmlsecurity/source/helper/makefile.mk
new file mode 100644
index 000000000000..0d5fec4a5bdb
--- /dev/null
+++ b/xmlsecurity/source/helper/makefile.mk
@@ -0,0 +1,90 @@
+#*************************************************************************
+#
+# $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=helper
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+# --- Files --------------------------------------------------------
+
+SLOFILES= \
+ $(SLO)$/xmlsignaturehelper.obj \
+ $(SLO)$/xmlsignaturehelper2.obj \
+ $(SLO)$/xsecctl.obj \
+ $(SLO)$/xsecparser.obj \
+ $(SLO)$/xsecsign.obj \
+ $(SLO)$/xsecverify.obj
+
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
new file mode 100644
index 000000000000..ffca2ddb6c78
--- /dev/null
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -0,0 +1,424 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignaturehelper.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 <xmlsecurity/xmlsignaturehelper.hxx>
+#include <xsecctl.hxx>
+
+#include <xmlsignaturehelper2.hxx>
+
+#include <tools/stream.hxx>
+#include <tools/debug.hxx>
+
+#include <xmloff/attrlist.hxx>
+
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+
+/* SEInitializer component */
+#define SEINITIALIZER_COMPONENT "com.sun.star.xml.crypto.SEInitializer"
+
+#define SIGFILEROOTELEMENT "all-signatures"
+
+using namespace ::com::sun::star;
+
+XMLSignatureHelper::XMLSignatureHelper( const uno::Reference< lang::XMultiServiceFactory>& rxMSF )
+ : mxMSF(rxMSF)
+{
+ mpXSecController = new XSecController;
+ mxSecurityController = mpXSecController;
+ mpXSecController->setFactory( rxMSF );
+ mbError = false;
+}
+
+XMLSignatureHelper::~XMLSignatureHelper()
+{
+ if (mxSEInitializer.is())
+ {
+ mxSEInitializer->freeSecurityContext( mxSecurityContext );
+ }
+}
+
+bool XMLSignatureHelper::Init( const rtl::OUString& rTokenPath )
+{
+ DBG_ASSERT( !mxSEInitializer.is(), "XMLSignatureHelper::Init - mxSEInitializer already set!" );
+ DBG_ASSERT( !mxSecurityContext.is(), "XMLSignatureHelper::Init - mxSecurityContext already set!" );
+
+ ImplCreateSEInitializer();
+ mxSecurityContext = mxSEInitializer->createSecurityContext( rTokenPath );
+ return mxSecurityContext.is();
+}
+
+void XMLSignatureHelper::ImplCreateSEInitializer()
+{
+ rtl::OUString sSEInitializer;
+
+ sSEInitializer = rtl::OUString::createFromAscii( SEINITIALIZER_COMPONENT );
+ mxSEInitializer = uno::Reference< com::sun::star::xml::crypto::XSEInitializer > (
+ mxMSF->createInstance( sSEInitializer ), uno::UNO_QUERY );
+}
+
+void XMLSignatureHelper::SetUriBinding( com::sun::star::uno::Reference< com::sun::star::xml::crypto::XUriBinding >& rxUriBinding )
+{
+ mxUriBinding = rxUriBinding;
+}
+
+void XMLSignatureHelper::SetStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStorage )
+{
+ DBG_ASSERT( !mxUriBinding.is(), "SetStorage - UriBinding already set!" );
+ mxUriBinding = new UriBindingHelper( rxStorage );
+}
+
+
+void XMLSignatureHelper::SetStartVerifySignatureHdl( const Link& rLink )
+{
+ maStartVerifySignatureHdl = rLink;
+}
+
+
+void XMLSignatureHelper::StartMission()
+{
+ if ( !mxUriBinding.is() )
+ mxUriBinding = new UriBindingHelper();
+
+ mpXSecController->startMission( mxUriBinding, mxSecurityContext );
+}
+
+void XMLSignatureHelper::EndMission()
+{
+ mpXSecController->endMission();
+}
+
+sal_Int32 XMLSignatureHelper::GetNewSecurityId()
+{
+ return mpXSecController->getNewSecurityId();
+}
+
+void XMLSignatureHelper::SetX509Certificate(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouX509IssuerName,
+ const rtl::OUString& ouX509SerialNumber)
+{
+ mpXSecController->setX509Certificate(
+ nSecurityId,
+ ouX509IssuerName,
+ ouX509SerialNumber);
+}
+
+void XMLSignatureHelper::SetDateTime(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouDate,
+ const rtl::OUString& ouTime)
+{
+ mpXSecController->setDateTime(
+ nSecurityId,
+ ouDate,
+ ouTime);
+}
+
+void XMLSignatureHelper::AddForSigning( sal_Int32 nSecurityId, const rtl::OUString& uri, const rtl::OUString& objectURL, sal_Bool bBinary )
+{
+ mpXSecController->signAStream( nSecurityId, uri, objectURL, bBinary );
+}
+
+uno::Reference<xml::sax::XDocumentHandler> XMLSignatureHelper::CreateDocumentHandlerWithHeader(
+ const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream )
+{
+ /*
+ * get SAX writer component
+ */
+ uno::Reference< io::XActiveDataSource > xSaxWriter(
+ mxMSF->createInstance(rtl::OUString::createFromAscii(
+ "com.sun.star.xml.sax.Writer")),
+ uno::UNO_QUERY );
+
+ DBG_ASSERT( xSaxWriter.is(), "can't instantiate XML writer" );
+
+ /*
+ * connect XML writer to output stream
+ */
+ xSaxWriter->setOutputStream( xOutputStream );
+
+ /*
+ * prepare document handler
+ */
+ uno::Reference<xml::sax::XDocumentHandler>
+ xDocHandler( xSaxWriter,uno::UNO_QUERY);
+
+ /*
+ * write the xml context for signatures
+ */
+ rtl::OUString tag_AllSignatures(RTL_CONSTASCII_USTRINGPARAM(SIGFILEROOTELEMENT));
+
+ xDocHandler->startDocument();
+ xDocHandler->startElement(
+ tag_AllSignatures,
+ uno::Reference< xml::sax::XAttributeList > (new SvXMLAttributeList()));
+
+ return xDocHandler;
+}
+
+void XMLSignatureHelper::CloseDocumentHandler( const uno::Reference<xml::sax::XDocumentHandler>& xDocumentHandler )
+{
+ rtl::OUString tag_AllSignatures(RTL_CONSTASCII_USTRINGPARAM(SIGFILEROOTELEMENT));
+ xDocumentHandler->endElement( tag_AllSignatures );
+ xDocumentHandler->endDocument();
+}
+
+void XMLSignatureHelper::ExportSignature(
+ const uno::Reference< xml::sax::XDocumentHandler >& xDocumentHandler,
+ const SignatureInformation& signatureInfo )
+{
+ mpXSecController->exportSignature(xDocumentHandler, signatureInfo);
+}
+
+bool XMLSignatureHelper::CreateAndWriteSignatue( const uno::Reference< xml::sax::XDocumentHandler >& xDocumentHandler )
+{
+ mbError = false;
+
+ /*
+ * create a signature listener
+ */
+ ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(
+ LINK( this, XMLSignatureHelper, SignatureCreationResultListener ),
+ LINK( this, XMLSignatureHelper, SignatureVerifyResultListener ),
+ LINK( this, XMLSignatureHelper, StartVerifySignatureElement ) );
+
+ /*
+ * configure the signature creation listener
+ */
+ //mpXSecController->setSignatureCreationResultListener( pSignatureListener );
+
+ /*
+ * write signatures
+ */
+ if ( !mpXSecController->WriteSignatue( xDocumentHandler ) )
+ {
+ mbError = true;
+ }
+
+ /*
+ * clear up the signature creation listener
+ */
+ //mpXSecController->setSignatureCreationResultListener( NULL );
+
+ return !mbError;
+}
+
+bool XMLSignatureHelper::CreateAndWriteSignatue( const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream )
+{
+ uno::Reference<xml::sax::XDocumentHandler> xDocHandler
+ = CreateDocumentHandlerWithHeader(xOutputStream);
+
+ bool rc = CreateAndWriteSignatue( xDocHandler );
+
+ CloseDocumentHandler(xDocHandler);
+
+ return rc;
+}
+
+bool XMLSignatureHelper::ReadAndVerifySignatue( const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& xInputStream )
+{
+ mbError = false;
+
+ DBG_ASSERT(xInputStream.is(), "input stream missing");
+
+ /*
+ * prepare ParserInputSrouce
+ */
+ xml::sax::InputSource aParserInput;
+ // aParserInput.sSystemId = ouName;
+ aParserInput.aInputStream = xInputStream;
+
+ /*
+ * get SAX parser component
+ */
+ uno::Reference< xml::sax::XParser > xParser(
+ mxMSF->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
+ uno::UNO_QUERY );
+ DBG_ASSERT( xParser.is(), "Can't create parser" );
+
+ /*
+ * create a signature reader
+ */
+ uno::Reference< xml::sax::XDocumentHandler > xHandler
+ = mpXSecController->createSignatureReader( );
+
+ /*
+ * create a signature listener
+ */
+ ImplXMLSignatureListener* pSignatureListener = new ImplXMLSignatureListener(
+ LINK( this, XMLSignatureHelper, SignatureCreationResultListener ),
+ LINK( this, XMLSignatureHelper, SignatureVerifyResultListener ),
+ LINK( this, XMLSignatureHelper, StartVerifySignatureElement ) );
+
+ /*
+ * configure the signature verify listener
+ */
+ //mpXSecController->setSignatureVerifyResultListener( pSignatureListener );
+
+ /*
+ * setup the connection:
+ * Parser -> SignatureListener -> SignatureReader
+ */
+ pSignatureListener->setNextHandler(xHandler);
+ xParser->setDocumentHandler( pSignatureListener );
+
+ /*
+ * parser the stream
+ */
+ try
+ {
+ xParser->parseStream( aParserInput );
+ }
+ catch( xml::sax::SAXParseException& )
+ {
+ mbError = true;
+ }
+ catch( xml::sax::SAXException& )
+ {
+ mbError = true;
+ }
+ catch( com::sun::star::io::IOException& )
+ {
+ mbError = true;
+ }
+ catch( uno::Exception& )
+ {
+ mbError = true;
+ }
+
+ /*
+ * clear up the connection
+ */
+ pSignatureListener->setNextHandler( NULL );
+
+ /*
+ * clear up the signature verify listener
+ */
+ //mpXSecController->setSignatureVerifyResultListener( NULL );
+
+ /*
+ * release the signature reader
+ */
+ mpXSecController->releaseSignatureReader( );
+
+ return !mbError;
+}
+
+SignatureInformations XMLSignatureHelper::GetSignatureInformations() const
+{
+ return mpXSecController->getSignatureInformations();
+}
+
+uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > XMLSignatureHelper::GetSecurityEnvironment()
+{
+ return (mxSecurityContext.is()?(mxSecurityContext->getSecurityEnvironment()):NULL);
+}
+
+/*
+void XMLSignatureHelper::createSecurityContext( rtl::OUString tokenPath )
+{
+ if ( !mxSEInitializer.is() )
+ ImplCreateSEInitializer();
+
+ mxSecurityContext = mxSEInitializer->createSecurityContext(tokenPath);
+}
+
+void XMLSignatureHelper::freeSecurityContext()
+{
+ if ( !mxSEInitializer.is() )
+ ImplCreateSEInitializer();
+
+ mxSEInitializer->freeSecurityContext( mxSecurityContext );
+}
+*/
+
+IMPL_LINK( XMLSignatureHelper, SignatureCreationResultListener, XMLSignatureCreationResult*, pResult )
+{
+ maCreationResults.insert( maCreationResults.begin() + maCreationResults.size(), *pResult );
+ if ( pResult->nSignatureCreationResult != com::sun::star::xml::crypto::sax::SignatureCreationResult_CREATIONSUCCEED )
+ mbError = true;
+ return 0;
+}
+
+IMPL_LINK( XMLSignatureHelper, SignatureVerifyResultListener, XMLSignatureVerifyResult*, pResult )
+{
+ maVerifyResults.insert( maVerifyResults.begin() + maVerifyResults.size(), *pResult );
+ if ( pResult->nSignatureVerifyResult != com::sun::star::xml::crypto::sax::SignatureVerifyResult_VERIFYSUCCEED )
+ mbError = true;
+ return 0;
+}
+
+IMPL_LINK( XMLSignatureHelper, StartVerifySignatureElement, const uno::Reference< com::sun::star::xml::sax::XAttributeList >*, pAttrs )
+{
+ if ( !maStartVerifySignatureHdl.IsSet() || maStartVerifySignatureHdl.Call( (void*)pAttrs ) )
+ {
+ sal_Int32 nSignatureId = mpXSecController->getNewSecurityId();
+ mpXSecController->addSignature( nSignatureId );
+ }
+
+ return 0;
+}
+
+
+
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx
new file mode 100644
index 000000000000..750b6dbf6524
--- /dev/null
+++ b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx
@@ -0,0 +1,242 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignaturehelper2.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 <xmlsecurity/xmlsignaturehelper.hxx>
+#include <xmlsignaturehelper2.hxx>
+
+#include <unotools/streamhelper.hxx>
+
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+
+using namespace com::sun::star;
+
+ImplXMLSignatureListener::ImplXMLSignatureListener( const Link& rCreationResultListenerListener, const Link rVerifyResultListenerListener, const Link rStartSignatureElement )
+{
+ maCreationResultListenerListener = rCreationResultListenerListener;
+ maVerifyResultListenerListener = rVerifyResultListenerListener;
+ maStartVerifySignatureElementListener = rStartSignatureElement;
+
+}
+ImplXMLSignatureListener::~ImplXMLSignatureListener()
+{
+}
+
+void ImplXMLSignatureListener::setNextHandler(
+ uno::Reference< xml::sax::XDocumentHandler > xNextHandler)
+{
+ m_xNextHandler = xNextHandler;
+}
+
+void SAL_CALL ImplXMLSignatureListener::signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureCreationResult nResult )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ XMLSignatureCreationResult aResult( securityId, nResult );
+ maCreationResultListenerListener.Call( &aResult );
+}
+
+void SAL_CALL ImplXMLSignatureListener::signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureVerifyResult nResult )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ XMLSignatureVerifyResult aResult( securityId, nResult );
+ maVerifyResultListenerListener.Call( &aResult );
+}
+
+// ---------------------------------------------------------------------------------
+// XDocumentHandler
+// ---------------------------------------------------------------------------------
+void SAL_CALL ImplXMLSignatureListener::startDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->startDocument();
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::endDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->endDocument();
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::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)
+{
+ if ( aName == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Signature")) )
+ {
+ maStartVerifySignatureElementListener.Call( (void*)&xAttribs );
+ }
+
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->startElement( aName, xAttribs );
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::endElement( const rtl::OUString& aName )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->endElement( aName );
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::characters( const rtl::OUString& aChars )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->characters( aChars );
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->ignorableWhitespace( aWhitespaces );
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->processingInstruction( aTarget, aData );
+ }
+}
+
+void SAL_CALL ImplXMLSignatureListener::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)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->setDocumentLocator( xLocator );
+ }
+}
+
+// ---------------------------------------------------------------------------------
+// XUriBinding
+// ---------------------------------------------------------------------------------
+
+UriBindingHelper::UriBindingHelper()
+{
+}
+
+UriBindingHelper::UriBindingHelper( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStorage )
+{
+ mxStorage = rxStorage;
+}
+
+
+void SAL_CALL UriBindingHelper::setUriBinding( const rtl::OUString& uri, const uno::Reference< io::XInputStream >& aInputStream )
+ throw (uno::Exception, uno::RuntimeException)
+{
+}
+
+uno::Reference< io::XInputStream > SAL_CALL UriBindingHelper::getUriBinding( const rtl::OUString& uri )
+ throw (uno::Exception, uno::RuntimeException)
+{
+ uno::Reference< io::XInputStream > xInputStream;
+ if ( mxStorage.is() )
+ {
+ uno::Reference< io::XStream > xStream = OpenInputStream( mxStorage, uri );
+ xInputStream = uno::Reference< io::XInputStream >( xStream, uno::UNO_QUERY );
+ }
+ else
+ {
+ SvFileStream* pStream = new SvFileStream( uri, STREAM_READ );
+ pStream->Seek( STREAM_SEEK_TO_END );
+ ULONG nBytes = pStream->Tell();
+ pStream->Seek( STREAM_SEEK_TO_BEGIN );
+ SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
+ xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
+ }
+ return xInputStream;
+}
+
+uno::Reference < io::XStream > UriBindingHelper::OpenInputStream( uno::Reference < embed::XStorage >& rxStore, const rtl::OUString& rURI )
+{
+ uno::Reference < io::XStream > xStream;
+
+ sal_Int32 nSepPos = rURI.indexOf( '/' );
+ if ( nSepPos == -1 )
+ {
+ xStream = rxStore->openStreamElement( rURI, embed::ElementModes::READ );
+ }
+ else
+ {
+ rtl::OUString aStoreName = rURI.copy( 0, nSepPos );
+ rtl::OUString aElement = rURI.copy( nSepPos+1 );
+ uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aStoreName, embed::ElementModes::READ );
+ xStream = OpenInputStream( xSubStore, aElement );
+ }
+ return xStream;
+}
+
+
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.hxx b/xmlsecurity/source/helper/xmlsignaturehelper2.hxx
new file mode 100644
index 000000000000..f41bb3da6c9d
--- /dev/null
+++ b/xmlsecurity/source/helper/xmlsignaturehelper2.hxx
@@ -0,0 +1,164 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignaturehelper2.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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <tools/link.hxx>
+#include <rtl/ustring.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase3.hxx>
+
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureCreationResultListener.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultListener.hpp>
+
+namespace com {
+namespace sun {
+namespace star {
+namespace io {
+ class XStream;
+ class XOutputStream;
+ class XInputStream; }
+namespace embed {
+ class XStorage; }
+}}}
+
+class ImplXMLSignatureListener : public cppu::WeakImplHelper3
+<
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener,
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener,
+ com::sun::star::xml::sax::XDocumentHandler
+>
+{
+private:
+ Link maCreationResultListenerListener;
+ Link maVerifyResultListenerListener;
+ Link maStartVerifySignatureElementListener;
+
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
+
+public:
+ ImplXMLSignatureListener( const Link& rCreationResultListenerListener, const Link rVerifyResultListenerListener, const Link rStartVerifySignatureElement );
+ ~ImplXMLSignatureListener();
+
+ void setNextHandler(com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > xNextHandler);
+
+ // com::sun::star::xml::crypto::sax::XSignatureCreationResultListener
+ virtual void SAL_CALL signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureCreationResult creationResult )
+ throw (com::sun::star::uno::RuntimeException);
+
+ // com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener
+ virtual void SAL_CALL signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureVerifyResult verifyResult )
+ throw (com::sun::star::uno::RuntimeException);
+
+ // com::sun::star::xml::sax::XDocumentHandler
+ 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 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 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);
+};
+
+
+// ---------------------------------------------------------------------------------
+// XUriBinding
+// ---------------------------------------------------------------------------------
+
+class UriBindingHelper : public cppu::WeakImplHelper1
+<
+ com::sun::star::xml::crypto::XUriBinding
+>
+{
+private:
+ com::sun::star::uno::Reference < com::sun::star::embed::XStorage > mxStorage;
+
+public:
+ UriBindingHelper();
+ UriBindingHelper( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStorage );
+
+ void SAL_CALL setUriBinding( const rtl::OUString& uri, const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream )
+ throw (com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getUriBinding( const rtl::OUString& uri )
+ throw (com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ static com::sun::star::uno::Reference < com::sun::star::io::XStream > OpenInputStream( com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStore, const rtl::OUString& rURI );
+};
+
diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx
new file mode 100644
index 000000000000..9408b7378a74
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecctl.cxx
@@ -0,0 +1,1359 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecctl.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 <xsecctl.hxx>
+
+#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
+#include <tools/debug.hxx>
+#endif
+
+#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
+#include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
+#include <com/sun/star/xml/crypto/sax/SignatureVerifyResult.hpp>
+#include <com/sun/star/xml/crypto/sax/SignatureCreationResult.hpp>
+
+#include <xmloff/attrlist.hxx>
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxs = com::sun::star::xml::sax;
+namespace cssxw = com::sun::star::xml::wrapper;
+namespace cssb = com::sun::star::beans;
+
+/* bridge component names */
+#define XMLSIGNATURE_COMPONENT "com.sun.star.xml.crypto.XMLSignature"
+#define XMLDOCUMENTWRAPPER_COMPONENT "com.sun.star.xml.wrapper.XMLDocumentWrapper"
+
+/* xml security framework components */
+#define SAXEVENTKEEPER_COMPONENT "com.sun.star.xml.crypto.sax.SAXEventKeeper"
+
+/* string for package protocol */
+#define PACKAGEPROTOCOL "vnd.sun.star.Package:"
+
+XSecController::XSecController( )
+ :m_nNextSecurityId(1),
+ m_bIsSAXEventKeeperSticky(false),
+ m_bIsSAXEventKeeperConnected(false),
+ m_nStatusOfSecurityComponents(UNINITIALIZED),
+ m_pErrorMessage(NULL),
+ m_pXSecParser(NULL)
+{
+}
+
+XSecController::~XSecController()
+{
+}
+
+
+/*
+ * private methods
+ */
+int XSecController::findSignatureInfor( sal_Int32 nSecurityId)
+/****** XSecController/findSignatureInfor *************************************
+ *
+ * NAME
+ * findSignatureInfor -- find SignatureInformation struct for a particular
+ * signature
+ *
+ * SYNOPSIS
+ * index = findSignatureInfor( nSecurityId );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * nSecurityId - the signature's id
+ *
+ * RESULT
+ * index - the index of the signature, or -1 when no such signature
+ * existing
+ *
+ * HISTORY
+ * 08.05.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ int i;
+ int size = m_vInternalSignatureInformations.size();
+
+ for (i=0; i<size; ++i)
+ {
+ if (m_vInternalSignatureInformations[i].signatureInfor.nSecurityId == nSecurityId)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+void XSecController::createXSecComponent( )
+/****** XSecController/createXSecComponent ************************************
+ *
+ * NAME
+ * bResult = createXSecComponent -- creates xml security components
+ *
+ * SYNOPSIS
+ * createXSecComponent( );
+ *
+ * FUNCTION
+ * Creates xml security components, including:
+ * 1. an xml signature bridge component ( Java based or C based)
+ * 2. an XMLDocumentWrapper component ( Java based or C based)
+ * 3. a SAXEventKeeper component
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ rtl::OUString sSAXEventKeeper(rtl::OUString::createFromAscii( SAXEVENTKEEPER_COMPONENT ));
+ rtl::OUString sXMLSignature(rtl::OUString::createFromAscii( XMLSIGNATURE_COMPONENT ));
+ rtl::OUString sXMLDocument(rtl::OUString::createFromAscii( XMLDOCUMENTWRAPPER_COMPONENT ));
+
+ /*
+ * marks all security components are not available.
+ */
+ m_nStatusOfSecurityComponents = FAILTOINITIALIZED;
+ m_xXMLSignature = NULL;
+ m_xXMLDocumentWrapper = NULL;
+ m_xSAXEventKeeper = NULL;
+
+ m_xXMLSignature = cssu::Reference< cssxc::XXMLSignature >(
+ mxMSF->createInstance( sXMLSignature ),
+ cssu::UNO_QUERY );
+
+ bool bSuccess = (0!=m_xXMLSignature.is());
+ if ( bSuccess )
+ /*
+ * XMLSignature created successfully.
+ */
+ {
+ m_xXMLDocumentWrapper = cssu::Reference< cssxw::XXMLDocumentWrapper >(
+ mxMSF->createInstance( sXMLDocument ),
+ cssu::UNO_QUERY );
+ }
+
+ bSuccess &= (0!=m_xXMLDocumentWrapper.is());
+ if ( bSuccess )
+ /*
+ * XMLDocumentWrapper created successfully.
+ */
+ {
+ m_xSAXEventKeeper = cssu::Reference< cssxc::sax::XSecuritySAXEventKeeper >(
+ mxMSF->createInstance( sSAXEventKeeper ),
+ cssu::UNO_QUERY );
+ }
+
+ bSuccess &= (0!=m_xSAXEventKeeper.is());
+
+ if (bSuccess)
+ /*
+ * SAXEventKeeper created successfully.
+ */
+ {
+ cssu::Reference< cssl::XInitialization > xInitialization(m_xSAXEventKeeper, cssu::UNO_QUERY);
+
+ cssu::Sequence <cssu::Any> arg(1);
+ arg[0] = cssu::makeAny(m_xXMLDocumentWrapper);
+ xInitialization->initialize(arg);
+
+ cssu::Reference<cssxc::sax::XSAXEventKeeperStatusChangeBroadcaster>
+ xSAXEventKeeperStatusChangeBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY);
+ cssu::Reference< cssxc::sax::XSAXEventKeeperStatusChangeListener >
+ xStatusChangeListener = this;
+
+ xSAXEventKeeperStatusChangeBroadcaster
+ ->addXSAXEventKeeperStatusChangeListener( xStatusChangeListener );
+
+ m_nStatusOfSecurityComponents = INITIALIZED;
+ }
+}
+
+bool XSecController::chainOn( bool bRetrievingLastEvent )
+/****** XSecController/chainOn ************************************************
+ *
+ * NAME
+ * chainOn -- tyies to connect the SAXEventKeeper with the SAX chain.
+ *
+ * SYNOPSIS
+ * bJustChainingOn = chainOn( bRetrievingLastEvent );
+ *
+ * FUNCTION
+ * First, checks whether the SAXEventKeeper is on the SAX chain. If not,
+ * creates xml security components, and chains the SAXEventKeeper into
+ * the SAX chain.
+ * Before being chained in, the SAXEventKeeper needs to receive all
+ * missed key SAX events, which can promise the DOM tree bufferred by the
+ * SAXEventKeeper has the same structure with the original document.
+ *
+ * INPUTS
+ * bRetrievingLastEvent - whether to retrieve the last key SAX event from
+ * the ElementStackKeeper.
+ *
+ * RESULT
+ * bJustChainingOn - whether the SAXEventKeeper is just chained into the
+ * SAX chain.
+ *
+ * NOTES
+ * Sometimes, the last key SAX event can't be transferred to the
+ * SAXEventKeeper together.
+ * For instance, at the time an referenced element is detected, the
+ * startElement event has already been reserved by the ElementStackKeeper.
+ * Meanwhile, an ElementCollector needs to be created before the
+ * SAXEventKeeper receives that startElement event.
+ * So for the SAXEventKeeper, it needs to receive all missed key SAX
+ * events except that startElement event, then adds a new
+ * ElementCollector, then receives that startElement event.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ bool rc = false;
+
+ if (!m_bIsSAXEventKeeperSticky && !m_bIsSAXEventKeeperConnected)
+ {
+ if ( m_nStatusOfSecurityComponents == UNINITIALIZED )
+ {
+ createXSecComponent();
+ }
+
+ if ( m_nStatusOfSecurityComponents == INITIALIZED )
+ /*
+ * if all security components are ready, chains on the SAXEventKeeper
+ */
+ {
+ /*
+ * disconnect the SAXEventKeeper with its current output handler,
+ * to make sure no SAX event is forwarded during the connecting
+ * phase.
+ */
+ m_xSAXEventKeeper->setNextHandler( NULL );
+
+ cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(m_xSAXEventKeeper, cssu::UNO_QUERY);
+
+ /*
+ * connects the previous document handler on the SAX chain
+ */
+ if ( m_xPreviousNodeOnSAXChain.is() )
+ {
+ if ( m_bIsPreviousNodeInitializable )
+ {
+ cssu::Reference< cssl::XInitialization > xInitialization
+ (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
+
+ cssu::Sequence<cssu::Any> aArgs( 1 );
+ aArgs[0] <<= xSEKHandler;
+ xInitialization->initialize(aArgs);
+ }
+ else
+ {
+ cssu::Reference< cssxs::XParser > xParser
+ (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
+ xParser->setDocumentHandler( xSEKHandler );
+ }
+ }
+
+ /*
+ * get missed key SAX events
+ */
+ if (m_xElementStackKeeper.is())
+ {
+ m_xElementStackKeeper->retrieve(xSEKHandler, bRetrievingLastEvent);
+
+ /*
+ * now the ElementStackKeeper can stop its work, because the
+ * SAXEventKeeper is on the SAX chain, no SAX events will be
+ * missed.
+ */
+ m_xElementStackKeeper->stop();
+ }
+
+ /*
+ * connects the next document handler on the SAX chain
+ */
+ m_xSAXEventKeeper->setNextHandler( m_xNextNodeOnSAXChain );
+
+ m_bIsSAXEventKeeperConnected = true;
+
+ rc = true;
+ }
+ }
+
+ return rc;
+}
+
+void XSecController::chainOff()
+/****** XSecController/chainOff ***********************************************
+ *
+ * NAME
+ * chainOff -- disconnects the SAXEventKeeper from the SAX chain.
+ *
+ * SYNOPSIS
+ * chainOff( );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (!m_bIsSAXEventKeeperSticky )
+ {
+ if (m_bIsSAXEventKeeperConnected)
+ {
+ m_xSAXEventKeeper->setNextHandler( NULL );
+
+ if ( m_xPreviousNodeOnSAXChain.is() )
+ {
+ if ( m_bIsPreviousNodeInitializable )
+ {
+ cssu::Reference< cssl::XInitialization > xInitialization
+ (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
+
+ cssu::Sequence<cssu::Any> aArgs( 1 );
+ aArgs[0] <<= m_xNextNodeOnSAXChain;
+ xInitialization->initialize(aArgs);
+ }
+ else
+ {
+ cssu::Reference< cssxs::XParser > xParser(m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
+ xParser->setDocumentHandler( m_xNextNodeOnSAXChain );
+ }
+ }
+
+ if (m_xElementStackKeeper.is())
+ {
+ /*
+ * start the ElementStackKeeper to reserve any possible
+ * missed key SAX events
+ */
+ m_xElementStackKeeper->start();
+ }
+
+ m_bIsSAXEventKeeperConnected = false;
+ }
+ }
+}
+
+void XSecController::checkChainingStatus()
+/****** XSecController/checkChainingStatus ************************************
+ *
+ * NAME
+ * checkChainingStatus -- connects or disconnects the SAXEventKeeper
+ * according to the current situation.
+ *
+ * SYNOPSIS
+ * checkChainingStatus( );
+ *
+ * FUNCTION
+ * The SAXEventKeeper is chained into the SAX chain, when:
+ * 1. some element is being collected, or
+ * 2. the SAX event stream is blocking.
+ * Otherwise, chain off the SAXEventKeeper.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if ( m_bIsCollectingElement || m_bIsBlocking )
+ {
+ chainOn(true);
+ }
+ else
+ {
+ chainOff();
+ }
+}
+
+void XSecController::initializeSAXChain()
+/****** XSecController/initializeSAXChain *************************************
+ *
+ * NAME
+ * initializeSAXChain -- initializes the SAX chain according to the
+ * current setting.
+ *
+ * SYNOPSIS
+ * initializeSAXChain( );
+ *
+ * FUNCTION
+ * Initializes the SAX chain, if the SAXEventKeeper is asked to be always
+ * on the SAX chain, chains it on. Otherwise, starts the
+ * ElementStackKeeper to reserve key SAX events.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bIsSAXEventKeeperConnected = false;
+ m_bIsCollectingElement = false;
+ m_bIsBlocking = false;
+
+ if (m_xElementStackKeeper.is())
+ {
+ /*
+ * starts the ElementStackKeeper
+ */
+ m_xElementStackKeeper->start();
+ }
+
+ chainOff();
+}
+
+cssu::Reference< com::sun::star::io::XInputStream >
+ XSecController::getObjectInputStream( const rtl::OUString& objectURL )
+/****** XSecController/getObjectInputStream ************************************
+ *
+ * NAME
+ * getObjectInputStream -- get a XInputStream interface from a SvStorage
+ *
+ * SYNOPSIS
+ * xInputStream = getObjectInputStream( objectURL );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * objectURL - the object uri
+ *
+ * RESULT
+ * xInputStream - the XInputStream interface
+ *
+ * HISTORY
+ * 15.04.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ cssu::Reference< com::sun::star::io::XInputStream > xObjectInputStream;
+
+ DBG_ASSERT( m_xUriBinding.is(), "Need XUriBinding!" );
+
+ xObjectInputStream = m_xUriBinding->getUriBinding(objectURL);
+
+ return xObjectInputStream;
+}
+
+#if 0
+sal_Int32 XSecController::getFastPropertyIndex(sal_Int32 nHandle) const
+/****** XSecController/getFastPropertyIndex ***********************************
+ *
+ * NAME
+ * getFastPropertyIndex -- gets the index of a particular fast property
+ *
+ * SYNOPSIS
+ * nIndex = getFastPropertyIndex( nHandle );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * nHandle - the key for the fast property
+ *
+ * RESULT
+ * nIndex - the index of the fast property, or -1
+ * if the key is not found.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ std::vector< sal_Int32 >::const_iterator ii = m_vFastPropertyIndexs.begin();
+ sal_Int32 nIndex = 0;
+
+ bool bFound = false;
+
+ for( ; ii != m_vFastPropertyIndexs.end(); ++ii,++nIndex )
+ {
+ if ( nHandle == (*ii))
+ {
+ bFound = true;
+ break;
+ }
+ }
+
+ if (!bFound)
+ {
+ nIndex = -1;
+ }
+
+ return nIndex;
+}
+#endif
+
+/*
+ * public methods
+ */
+
+void XSecController::setFactory( const cssu::Reference<cssl::XMultiServiceFactory>& rxMSF)
+/****** XSecController/setFactory *********************************************
+ *
+ * NAME
+ * setFactory -- configures the service factory component.
+ *
+ * SYNOPSIS
+ * setFactory( rxMSF );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * rxMSF - the service factory component
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ mxMSF = rxMSF;
+}
+
+#if 0
+void XSecController::setSignatureCreationResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& xSignatureCreationResultListener)
+{
+ m_xSignatureCreationResultListener = xSignatureCreationResultListener;
+}
+
+void XSecController::setSignatureVerifyResultListener(
+ const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& xSignatureVerifyResultListener)
+{
+ m_xSignatureVerifyResultListener = xSignatureVerifyResultListener;
+}
+#endif
+
+sal_Int32 XSecController::getNewSecurityId( )
+{
+ sal_Int32 nId = m_nNextSecurityId;
+ m_nNextSecurityId++;
+ return nId;
+}
+
+void XSecController::startMission(
+ const cssu::Reference< cssxc::XUriBinding >& xUriBinding,
+ const cssu::Reference< cssxc::XXMLSecurityContext >& xSecurityContext )
+/****** XSecController/startMission *******************************************
+ *
+ * NAME
+ * startMission -- starts a new security mission.
+ *
+ * SYNOPSIS
+ * startMission( xUriBinding, xSecurityContect );
+ *
+ * FUNCTION
+ * get ready for a new mission.
+ *
+ * INPUTS
+ * xUriBinding - the Uri binding that provide maps between uris and
+ * XInputStreams
+ * xSecurityContext - the security context component which can provide
+ * cryptoken
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_xUriBinding = xUriBinding;
+
+ m_nStatusOfSecurityComponents = UNINITIALIZED;
+ m_xSecurityContext = xSecurityContext;
+ m_pErrorMessage = NULL;
+
+ m_vInternalSignatureInformations.clear();
+
+ m_bVerifyCurrentSignature = false;
+}
+
+void XSecController::setSAXChainConnector(
+ const cssu::Reference< cssl::XInitialization >& xInitialization,
+ const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler,
+ const cssu::Reference< cssxc::sax::XElementStackKeeper >& xElementStackKeeper)
+/****** XSecController/setSAXChainConnector ***********************************
+ *
+ * NAME
+ * setSAXChainConnector -- configures the components which will
+ * collaborate with the SAXEventKeeper on the SAX chain.
+ *
+ * SYNOPSIS
+ * setSAXChainConnector( xInitialization,
+ * xDocumentHandler,
+ * xElementStackKeeper );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * xInitialization - the previous node on the SAX chain
+ * xDocumentHandler - the next node on the SAX chain
+ * xElementStackKeeper - the ElementStackKeeper component which reserves
+ * missed key SAX events for the SAXEventKeeper
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bIsPreviousNodeInitializable = true;
+ m_xPreviousNodeOnSAXChain = xInitialization;
+ m_xNextNodeOnSAXChain = xDocumentHandler;
+ m_xElementStackKeeper = xElementStackKeeper;
+
+ initializeSAXChain( );
+}
+
+void XSecController::setSAXChainConnector(
+ const cssu::Reference< cssxs::XParser >& xParser,
+ const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler,
+ const cssu::Reference< cssxc::sax::XElementStackKeeper >& xElementStackKeeper)
+/****** XSecController/setSAXChainConnector ***********************************
+ *
+ * NAME
+ * setSAXChainConnector -- configures the components which will
+ * collaborate with the SAXEventKeeper on the SAX chain.
+ *
+ * SYNOPSIS
+ * setSAXChainConnector( xParser, xDocumentHandler, xElementStackKeeper );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * xParser - the previous node on the SAX chain
+ * xDocumentHandler - the next node on the SAX chain
+ * xElementStackKeeper -the ElementStackKeeper component which reserves
+ * missed key SAX events for the SAXEventKeeper
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_bIsPreviousNodeInitializable = false;
+ m_xPreviousNodeOnSAXChain = xParser;
+ m_xNextNodeOnSAXChain = xDocumentHandler;
+ m_xElementStackKeeper = xElementStackKeeper;
+
+ initializeSAXChain( );
+}
+
+void XSecController::clearSAXChainConnector()
+/****** XSecController/clearSAXChainConnector *********************************
+ *
+ * NAME
+ * clearSAXChainConnector -- resets the collaborating components.
+ *
+ * SYNOPSIS
+ * clearSAXChainConnector( );
+ *
+ * FUNCTION
+ * See NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ /*
+ * before reseting, if the ElementStackKeeper has kept something, then
+ * those kept key SAX events must be transferred to the SAXEventKeeper
+ * first. This is to promise the next node to the SAXEventKeeper on the
+ * SAX chain always receives a complete document.
+ */
+ if (m_xElementStackKeeper.is() && m_xSAXEventKeeper.is())
+ {
+ cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(m_xSAXEventKeeper, cssu::UNO_QUERY);
+ m_xElementStackKeeper->retrieve(xSEKHandler, sal_True);
+ }
+
+ chainOff();
+
+ m_xPreviousNodeOnSAXChain = NULL;
+ m_xNextNodeOnSAXChain = NULL;
+ m_xElementStackKeeper = NULL;
+}
+
+void XSecController::endMission()
+/****** XSecController/endMission *********************************************
+ *
+ * NAME
+ * endMission -- forces to end all missions
+ *
+ * SYNOPSIS
+ * endMission( );
+ *
+ * FUNCTION
+ * Deletes all signature information and forces all missions to an end.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ sal_Int32 size = m_vInternalSignatureInformations.size();
+
+ for (int i=0; i<size; ++i)
+ {
+ if ( m_nStatusOfSecurityComponents == INITIALIZED )
+ /*
+ * ResolvedListener only exist when the security components are created.
+ */
+ {
+ cssu::Reference< cssxc::sax::XMissionTaker > xMissionTaker
+ ( m_vInternalSignatureInformations[i].xReferenceResolvedListener, cssu::UNO_QUERY );
+
+ /*
+ * askes the SignatureCreator/SignatureVerifier to release
+ * all resouces it uses.
+ */
+ xMissionTaker->endMission();
+ }
+ }
+
+ m_xUriBinding = NULL;
+ m_xSecurityContext = NULL;
+
+ /*
+ * free the status change listener reference to this object
+ */
+ if (m_xSAXEventKeeper.is())
+ {
+ cssu::Reference<cssxc::sax::XSAXEventKeeperStatusChangeBroadcaster>
+ xSAXEventKeeperStatusChangeBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY);
+ xSAXEventKeeperStatusChangeBroadcaster
+ ->addXSAXEventKeeperStatusChangeListener( NULL );
+ }
+}
+
+const char* XSecController::getErrorMessage()
+/****** XSecController/getErrorMessage ****************************************
+ *
+ * NAME
+ * getErrorMessage -- get the last error message
+ *
+ * SYNOPSIS
+ * pErrorMessage = getErrorMessage( );
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 22.04.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return m_pErrorMessage;
+}
+
+void XSecController::exportSignature(
+ const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler,
+ const SignatureInformation& signatureInfo )
+/****** XSecController/exportSignature ****************************************
+ *
+ * NAME
+ * exportSignature -- export a signature structure to an XDocumentHandler
+ *
+ * SYNOPSIS
+ * exportSignature( xDocumentHandler, signatureInfo);
+ *
+ * FUNCTION
+ * see NAME.
+ *
+ * INPUTS
+ * xDocumentHandler - the document handler to receive the signature
+ * signatureInfo - signature to be exported
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 26.05.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ /*
+ * defines all element tags in Signature element.
+ */
+ rtl::OUString tag_Signature(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNATURE));
+ rtl::OUString tag_SignedInfo(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNEDINFO));
+ rtl::OUString tag_CanonicalizationMethod(RTL_CONSTASCII_USTRINGPARAM(TAG_CANONICALIZATIONMETHOD));
+ rtl::OUString tag_SignatureMethod(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNATUREMETHOD));
+ rtl::OUString tag_Reference(RTL_CONSTASCII_USTRINGPARAM(TAG_REFERENCE));
+ rtl::OUString tag_Transforms(RTL_CONSTASCII_USTRINGPARAM(TAG_TRANSFORMS));
+ rtl::OUString tag_Transform(RTL_CONSTASCII_USTRINGPARAM(TAG_TRANSFORM));
+ rtl::OUString tag_DigestMethod(RTL_CONSTASCII_USTRINGPARAM(TAG_DIGESTMETHOD));
+ rtl::OUString tag_DigestValue(RTL_CONSTASCII_USTRINGPARAM(TAG_DIGESTVALUE));
+ rtl::OUString tag_SignatureValue(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNATUREVALUE));
+ rtl::OUString tag_KeyInfo(RTL_CONSTASCII_USTRINGPARAM(TAG_KEYINFO));
+ rtl::OUString tag_X509Data(RTL_CONSTASCII_USTRINGPARAM(TAG_X509DATA));
+ rtl::OUString tag_X509IssuerSerial(RTL_CONSTASCII_USTRINGPARAM(TAG_X509ISSUERSERIAL));
+ rtl::OUString tag_X509IssuerName(RTL_CONSTASCII_USTRINGPARAM(TAG_X509ISSUERNAME));
+ rtl::OUString tag_X509SerialNumber(RTL_CONSTASCII_USTRINGPARAM(TAG_X509SERIALNUMBER));
+ rtl::OUString tag_X509Certificate(RTL_CONSTASCII_USTRINGPARAM(TAG_X509CERTIFICATE));
+
+ rtl::OUString tag_Object(RTL_CONSTASCII_USTRINGPARAM(TAG_OBJECT));
+ rtl::OUString tag_SignatureProperties(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNATUREPROPERTIES));
+ rtl::OUString tag_SignatureProperty(RTL_CONSTASCII_USTRINGPARAM(TAG_SIGNATUREPROPERTY));
+ rtl::OUString tag_Timestamp(RTL_CONSTASCII_USTRINGPARAM(TAG_TIMESTAMP));
+ rtl::OUString tag_Date(RTL_CONSTASCII_USTRINGPARAM(TAG_DATE));
+ rtl::OUString tag_Time(RTL_CONSTASCII_USTRINGPARAM(TAG_TIME));
+
+ const SignatureReferenceInformations& vReferenceInfors = signatureInfo.vSignatureReferenceInfors;
+ SvXMLAttributeList *pAttributeList;
+
+ /*
+ * Write Signature element
+ */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_XMLNS)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(NS_XMLDSIG)));
+
+ if (signatureInfo.ouSignatureId.getLength()>0)
+ {
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ID)),
+ rtl::OUString(signatureInfo.ouSignatureId));
+ }
+
+ xDocumentHandler->startElement( tag_Signature, cssu::Reference< cssxs::XAttributeList > (pAttributeList));
+ {
+ /* Write SignedInfo element */
+ xDocumentHandler->startElement(
+ tag_SignedInfo,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write CanonicalizationMethod element */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ALGORITHM)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ALGO_C14N)));
+ xDocumentHandler->startElement( tag_CanonicalizationMethod, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
+ xDocumentHandler->endElement( tag_CanonicalizationMethod );
+
+ /* Write SignatureMethod element */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ALGORITHM)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ALGO_RSASHA1)));
+ xDocumentHandler->startElement( tag_SignatureMethod, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
+ xDocumentHandler->endElement( tag_SignatureMethod );
+
+ /* Write Reference element */
+ int j;
+ int refNum = vReferenceInfors.size();
+
+ for(j=0; j<refNum; ++j)
+ {
+ const SignatureReferenceInformation& refInfor = vReferenceInfors[j];
+
+ pAttributeList = new SvXMLAttributeList();
+ if ( refInfor.nType != 1 )
+ /*
+ * stream reference
+ */
+ {
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_URI)),
+ refInfor.ouURI);
+ }
+ else
+ /*
+ * same-document reference
+ */
+ {
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_URI)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_FRAGMENT))+refInfor.ouURI);
+ }
+
+ xDocumentHandler->startElement( tag_Reference, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
+ {
+ /* Write Transforms element */
+ if (refInfor.nType == 3)
+ /*
+ * xml stream, so c14n transform is needed
+ */
+ {
+ xDocumentHandler->startElement(
+ tag_Transforms,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ALGORITHM)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ALGO_C14N)));
+ xDocumentHandler->startElement(
+ tag_Transform,
+ cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
+ xDocumentHandler->endElement( tag_Transform );
+ }
+ xDocumentHandler->endElement( tag_Transforms );
+ }
+
+ /* Write DigestMethod element */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ALGORITHM)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ALGO_XMLDSIGSHA1)));
+ xDocumentHandler->startElement(
+ tag_DigestMethod,
+ cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
+ xDocumentHandler->endElement( tag_DigestMethod );
+
+ /* Write DigestValue element */
+ xDocumentHandler->startElement(
+ tag_DigestValue,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( refInfor.ouDigestValue );
+ xDocumentHandler->endElement( tag_DigestValue );
+ }
+ xDocumentHandler->endElement( tag_Reference );
+ }
+ }
+ xDocumentHandler->endElement( tag_SignedInfo );
+
+ /* Write SignatureValue element */
+ xDocumentHandler->startElement(
+ tag_SignatureValue,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouSignatureValue );
+ xDocumentHandler->endElement( tag_SignatureValue );
+
+ /* Write KeyInfo element */
+ xDocumentHandler->startElement(
+ tag_KeyInfo,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write X509Data element */
+ xDocumentHandler->startElement(
+ tag_X509Data,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write X509IssuerSerial element */
+ xDocumentHandler->startElement(
+ tag_X509IssuerSerial,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write X509IssuerName element */
+ xDocumentHandler->startElement(
+ tag_X509IssuerName,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouX509IssuerName );
+ xDocumentHandler->endElement( tag_X509IssuerName );
+
+ /* Write X509SerialNumber element */
+ xDocumentHandler->startElement(
+ tag_X509SerialNumber,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouX509SerialNumber );
+ xDocumentHandler->endElement( tag_X509SerialNumber );
+ }
+ xDocumentHandler->endElement( tag_X509IssuerSerial );
+
+ /* Write X509Certificate element */
+ if (signatureInfo.ouX509Certificate.getLength()>0)
+ {
+ xDocumentHandler->startElement(
+ tag_X509Certificate,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouX509Certificate );
+ xDocumentHandler->endElement( tag_X509Certificate );
+ }
+ }
+ xDocumentHandler->endElement( tag_X509Data );
+ }
+ xDocumentHandler->endElement( tag_KeyInfo );
+
+ if (signatureInfo.ouDate.getLength()>0 ||signatureInfo.ouTime.getLength()>0)
+ {
+ /* Write Object element */
+ xDocumentHandler->startElement(
+ tag_Object,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write SignatureProperties element */
+ xDocumentHandler->startElement(
+ tag_SignatureProperties,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ {
+ /* Write SignatureProperty element */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_ID)),
+ signatureInfo.ouPropertyId);
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_TARGET)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_FRAGMENT))+signatureInfo.ouSignatureId);
+ xDocumentHandler->startElement(
+ tag_SignatureProperty,
+ cssu::Reference< cssxs::XAttributeList > (pAttributeList));
+ {
+ /* Write timestamp element */
+ pAttributeList = new SvXMLAttributeList();
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ATTR_XMLNS)),
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(NS_DATETIME)));
+ xDocumentHandler->startElement(
+ tag_Timestamp,
+ cssu::Reference< cssxs::XAttributeList > (pAttributeList));
+ {
+ /* Write date element */
+ xDocumentHandler->startElement(
+ tag_Date,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouDate );
+ xDocumentHandler->endElement( tag_Date );
+
+ /* Write time element */
+ xDocumentHandler->startElement(
+ tag_Time,
+ cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
+ xDocumentHandler->characters( signatureInfo.ouTime );
+ xDocumentHandler->endElement( tag_Time );
+ }
+ xDocumentHandler->endElement( tag_Timestamp );
+ }
+ xDocumentHandler->endElement( tag_SignatureProperty );
+ }
+ xDocumentHandler->endElement( tag_SignatureProperties );
+ }
+ xDocumentHandler->endElement( tag_Object );
+ }
+ }
+ xDocumentHandler->endElement( tag_Signature );
+}
+
+bool XSecController::getSignatureInfor( sal_Int32 nSecurityId, SignatureInformation& signatureInfor )
+{
+ int index = findSignatureInfor(nSecurityId);
+ if (index == -1)
+ {
+ return false;
+ }
+ else
+ {
+ signatureInfor = m_vInternalSignatureInformations[index].signatureInfor;
+ return true;
+ }
+}
+
+SignatureInformations XSecController::getSignatureInformations()
+{
+ SignatureInformations vInfors;
+ int sigNum = m_vInternalSignatureInformations.size();
+
+ for (int i=0; i<sigNum; ++i)
+ {
+ SignatureInformation si = m_vInternalSignatureInformations[i].signatureInfor;
+ vInfors.push_back(si);
+ }
+
+ return vInfors;
+}
+
+/*
+ * XSecurityController
+ *
+ * no methods
+ */
+
+/*
+ * XFastPropertySet
+ */
+/*
+void SAL_CALL XSecController::setFastPropertyValue(
+ sal_Int32 nHandle,
+ const cssu::Any& aValue )
+ throw ( cssb::UnknownPropertyException,
+ cssb::PropertyVetoException,
+ cssl::IllegalArgumentException,
+ cssl::WrappedTargetException,
+ cssu::RuntimeException)
+{
+ sal_Int32 nIndex = getFastPropertyIndex(nHandle);
+ if (nIndex == -1)
+ {
+ m_vFastPropertyIndexs.push_back( nHandle );
+ m_vFastPropertyValues.push_back( aValue );
+ }
+ else
+ {
+ m_vFastPropertyValues[nIndex] = aValue;
+ }
+}
+
+cssu::Any SAL_CALL XSecController::getFastPropertyValue(
+ sal_Int32 nHandle )
+ throw (
+ cssb::UnknownPropertyException,
+ cssl::WrappedTargetException,
+ cssu::RuntimeException)
+{
+ cssu::Any aValue;
+
+ sal_Int32 nIndex = getFastPropertyIndex(nHandle);
+ if (nIndex != -1)
+ {
+ aValue = m_vFastPropertyValues[nIndex];
+ }
+
+ return aValue;
+}
+*/
+
+/*
+ * XSAXEventKeeperStatusChangeListener
+ */
+
+void SAL_CALL XSecController::blockingStatusChanged( sal_Bool isBlocking )
+ throw (cssu::RuntimeException)
+{
+ /*
+ showMessageBox( rtl::OUString::createFromAscii((isBlocking?
+ "Blocking Status => TRUE":
+ "Blocking Status => FALSE")),
+ rtl::OUString::createFromAscii("SAXEventKeeper Status"));
+ */
+
+ this->m_bIsBlocking = isBlocking;
+ checkChainingStatus();
+}
+
+void SAL_CALL XSecController::collectionStatusChanged(
+ sal_Bool isInsideCollectedElement )
+ throw (cssu::RuntimeException)
+{
+ /*
+ showMessageBox( rtl::OUString::createFromAscii((isInsideCollectedElement?
+ "Collection Status => TRUE":
+ "Collection Status => FALSE")),
+ rtl::OUString::createFromAscii("SAXEventKeeper Status"));
+ */
+
+ this->m_bIsCollectingElement = isInsideCollectedElement;
+ checkChainingStatus();
+}
+
+void SAL_CALL XSecController::bufferStatusChanged( sal_Bool isBufferEmpty )
+ throw (cssu::RuntimeException)
+{
+ /*
+ showMessageBox( rtl::OUString::createFromAscii((isBufferEmpty?
+ "Buffer Empty => TRUE":
+ "Buffer Empty => FALSE")),
+ rtl::OUString::createFromAscii("SAXEventKeeper Status"));
+ */
+}
+
+/*
+ * XSignatureCreationResultListener
+ */
+void SAL_CALL XSecController::signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureCreationResult nResult )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ int index = findSignatureInfor(securityId);
+ DBG_ASSERT( index != -1, "Signature Not Found!" );
+
+ SignatureInformation& signatureInfor = m_vInternalSignatureInformations[index].signatureInfor;
+
+ if (nResult == cssxc::sax::SignatureCreationResult_CREATIONSUCCEED)
+ {
+ signatureInfor.nStatus = STATUS_CREATION_SUCCEED;
+ }
+ else
+ {
+ signatureInfor.nStatus = STATUS_CREATION_FAIL;
+ }
+}
+
+/*
+ * XSignatureVerifyResultListener
+ */
+void SAL_CALL XSecController::signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureVerifyResult nResult )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ int index = findSignatureInfor(securityId);
+ DBG_ASSERT( index != -1, "Signature Not Found!" );
+
+ SignatureInformation& signatureInfor = m_vInternalSignatureInformations[index].signatureInfor;
+
+ if (nResult == cssxc::sax::SignatureVerifyResult_VERIFYSUCCEED)
+ {
+ signatureInfor.nStatus = STATUS_VERIFY_SUCCEED;
+ }
+ else
+ {
+ signatureInfor.nStatus = STATUS_VERIFY_FAIL;
+ }
+}
diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx
new file mode 100644
index 000000000000..7d3a939f93af
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecctl.hxx
@@ -0,0 +1,580 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecctl.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 _XSEC_CTL_HXX
+#define _XSEC_CTL_HXX
+
+#include <xmlsecurity/sigstruct.hxx>
+
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/crypto/XXMLSignature.hpp>
+#include <com/sun/star/xml/crypto/XSEInitializer.hpp>
+#include <com/sun/star/xml/crypto/sax/XSecurityController.hpp>
+#include <com/sun/star/xml/crypto/sax/XElementStackKeeper.hpp>
+#include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
+#include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureCreationResultListener.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultListener.hpp>
+#include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+
+#include <cppuhelper/implbase4.hxx>
+
+#ifndef INCLUDED_VECTOR
+#include <vector>
+#define INCLUDED_VECTOR
+#endif
+
+/*
+ * all error information
+ */
+#define ERROR_CANNOTCREATEXMLSECURITYCOMPONENT "Can't create XML security components."
+#define ERROR_SAXEXCEPTIONDURINGCREATION "A SAX exception is throwed during signature creation."
+#define ERROR_IOEXCEPTIONDURINGCREATION "An IO exception is throwed during signature creation."
+#define ERROR_EXCEPTIONDURINGCREATION "An exception is throwed during signature creation."
+
+/*
+ * all stringS in signature element
+ */
+#define TAG_SIGNATURE "Signature"
+#define TAG_SIGNEDINFO "SignedInfo"
+#define TAG_CANONICALIZATIONMETHOD "CanonicalizationMethod"
+#define TAG_SIGNATUREMETHOD "SignatureMethod"
+#define TAG_REFERENCE "Reference"
+#define TAG_TRANSFORMS "Transforms"
+#define TAG_TRANSFORM "Transform"
+#define TAG_DIGESTMETHOD "DigestMethod"
+#define TAG_DIGESTVALUE "DigestValue"
+#define TAG_SIGNATUREVALUE "SignatureValue"
+#define TAG_KEYINFO "KeyInfo"
+#define TAG_X509DATA "X509Data"
+#define TAG_X509ISSUERSERIAL "X509IssuerSerial"
+#define TAG_X509ISSUERNAME "X509IssuerName"
+#define TAG_X509SERIALNUMBER "X509SerialNumber"
+#define TAG_X509CERTIFICATE "X509Certificate"
+#define TAG_OBJECT "Object"
+#define TAG_SIGNATUREPROPERTIES "SignatureProperties"
+#define TAG_SIGNATUREPROPERTY "SignatureProperty"
+#define TAG_TIMESTAMP "timestamp"
+#define TAG_DATE "date"
+#define TAG_TIME "time"
+
+#define ATTR_XMLNS "xmlns"
+#define ATTR_ALGORITHM "Algorithm"
+#define ATTR_URI "URI"
+#define ATTR_ID "Id"
+#define ATTR_TARGET "Target"
+
+#define NS_XMLDSIG "http://www.w3.org/2000/09/xmldsig#"
+#define NS_DATETIME "http://www.ietf.org/rfcXXXX.txt"
+
+#define ALGO_C14N "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
+#define ALGO_RSASHA1 "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
+#define ALGO_XMLDSIGSHA1 "http://www.w3.org/2000/09/xmldsig#sha1"
+
+#define CHAR_FRAGMENT "#"
+#define CHAR_BLANK " "
+
+
+/*
+ * status of security related components
+ */
+#define UNINITIALIZED 0
+#define INITIALIZED 1
+#define FAILTOINITIALIZED 2
+
+#define RTL_ASCII_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_ASCII_US
+
+class InternalSignatureInformation
+{
+public:
+ SignatureInformation signatureInfor;
+
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener >
+ xReferenceResolvedListener;
+
+ ::std::vector< sal_Int32 > vKeeperIds;
+
+ InternalSignatureInformation(
+ sal_Int32 nId,
+ com::sun::star::uno::Reference< com::sun::star::xml::crypto::sax::XReferenceResolvedListener >
+ xListener)
+ :signatureInfor(nId)
+ {
+ xReferenceResolvedListener = xListener;
+ }
+
+ void addReference( sal_Int32 type, rtl::OUString uri, sal_Int32 keeperId )
+ {
+ signatureInfor.vSignatureReferenceInfors.push_back(
+ SignatureReferenceInformation(type, uri));
+ vKeeperIds.push_back( keeperId );
+ }
+};
+
+typedef ::std::vector< InternalSignatureInformation > InternalSignatureInformations;
+
+class XSecController : public cppu::WeakImplHelper4
+<
+ com::sun::star::xml::crypto::sax::XSecurityController,
+ //com::sun::star::beans::XFastPropertySet,
+ com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener,
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener,
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener
+>
+/****** XSecController.hxx/CLASS XSecController *******************************
+ *
+ * NAME
+ * XSecController -- the xml security framework controller
+ *
+ * FUNCTION
+ * Controlls the whole xml security framework to create signatures or to
+ * verify signatures.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XSecurityController,
+ * XFastPropertySet, XSAXEventKeeperStatusChangeListener,
+ * XSignatureCreationResultListener,
+ * XSignatureVerifyResultListener
+ *
+ * NOTES
+ * The XFastPropertySet interface is used to transfer common values to
+ * classes in other module, for instance, the signature id for all
+ * sessions is transferred to xmloff module through this interface.
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ friend class XSecParser;
+
+private:
+ com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory> mxMSF;
+
+ /*
+ * used to buffer SAX events
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLDocumentWrapper > m_xXMLDocumentWrapper;
+
+ /*
+ * the SAX events keeper
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper > m_xSAXEventKeeper;
+
+ /*
+ * the bridge component which creates/verifies signature
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSignature > m_xXMLSignature;
+
+ /*
+ * the Security Context
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSecurityContext > m_xSecurityContext;
+
+#if 0
+ /*
+ * the signature creation result listener
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener > m_xSignatureCreationResultListener;
+ /*
+ * the signature verify result listener
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener > m_xSignatureVerifyResultListener;
+#endif
+
+ /*
+ * the security id incrementer, in order to make any security id unique
+ * to the SAXEventKeeper.
+ * Because each XSecController has its own SAXEventKeeper, so this variable
+ * is not necessary to be static.
+ */
+ sal_Int32 m_nNextSecurityId;
+
+ /*
+ * Signature information
+ */
+ InternalSignatureInformations m_vInternalSignatureInformations;
+
+ /*
+ * the previous node on the SAX chain.
+ * The reason that use a Reference<XInterface> type variable
+ * is that the previous components are different when exporting
+ * and importing, and there is no other common interface they
+ * can provided.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::uno::XInterface > m_xPreviousNodeOnSAXChain;
+ /*
+ * whether the preivous node can provide an XInitiazlize interface,
+ * use this variable in order to typecast the XInterface to the
+ * correct interface type.
+ */
+ bool m_bIsPreviousNodeInitializable;
+
+ /*
+ * the next node on the SAX chain.
+ * it can always provide an XDocumentHandler interface.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xNextNodeOnSAXChain;
+
+ /*
+ * the ElementStackKeeper is used to reserve the key SAX events.
+ * when the SAXEventKeeper is chained on the SAX chain, it need
+ * first get all missed key SAX events in order to make sure the
+ * DOM tree it buffering has the same structure with the original
+ * document.
+ *
+ * For a given section of a SAX event stream, the key SAX events
+ * are the minimal SAX event subset of that section, which,
+ * combining with SAX events outside of this section, has the same
+ * structure with the original document.
+ *
+ * For example, sees the following dom fragment:
+ * <A>
+ * <B/>
+ * <C>
+ * <D>
+ * <E/>
+ * </D>
+ * </C>
+ * </A>
+ *
+ * If we consider the SAX event section from startElement(<A>) to
+ * startElement(<D>), then the key SAX events are:
+ *
+ * startElement(<A>), startElement(<C>), startElement(<D>)
+ *
+ * The startElement(<B>) and endElement(<B>) is ignored, because
+ * they are unimportant for the tree structure in this section.
+ *
+ * If we consider the SAX event section from startElement(<D>) to
+ * endElement(<A>), the key SAX events are:
+ *
+ * startElement(<D>), endElement(<D>), endElement(<C>),
+ * endElement(<A>).
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XElementStackKeeper > m_xElementStackKeeper;
+
+ /*
+ * a flag representing whether the SAXEventKeeper is now on the
+ * SAX chain.
+ */
+ bool m_bIsSAXEventKeeperConnected;
+
+ /*
+ * a flag representing whether it is collecting some element,
+ * which means that the SAXEventKeeper can't be chained off the
+ * SAX chain.
+ */
+ bool m_bIsCollectingElement;
+
+ /*
+ * a flag representing whether the SAX event stream is blocking,
+ * which also means that the SAXEventKeeper can't be chained off
+ * the SAX chain.
+ */
+ bool m_bIsBlocking;
+
+ /*
+ * a flag representing the current status of security related
+ * components.
+ */
+ sal_Int32 m_nStatusOfSecurityComponents;
+
+ /*
+ * a flag representing whether the SAXEventKeeper need to be
+ * on the SAX chain all the time.
+ * This flag is used to the situation when creating signature.
+ */
+ bool m_bIsSAXEventKeeperSticky;
+
+ /*
+ * fast property vector
+ */
+ std::vector< sal_Int32 > m_vFastPropertyIndexs;
+ std::vector< com::sun::star::uno::Any > m_vFastPropertyValues;
+
+ /*
+ * error message pointer
+ */
+ const char *m_pErrorMessage;
+
+ /*
+ * the XSecParser which is used to parse the signature stream
+ */
+ XSecParser *m_pXSecParser;
+
+ /*
+ * the caller assigned signature id for the next signature in the
+ * signature stream
+ */
+ sal_Int32 m_nReservedSignatureId;
+
+ /*
+ * representing whether to verify the current signature
+ */
+ bool m_bVerifyCurrentSignature;
+public:
+ /*
+ * An xUriBinding is provided to map Uris to XInputStream interfaces.
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XUriBinding > m_xUriBinding;
+
+private:
+
+ /*
+ * Common methods
+ */
+ void createXSecComponent( );
+ int findSignatureInfor( sal_Int32 nSecurityId );
+ bool chainOn( bool bRetrievingLastEvent );
+ void chainOff();
+ void checkChainingStatus();
+ void initializeSAXChain();
+
+ com::sun::star::uno::Reference<
+ com::sun::star::io::XInputStream > getObjectInputStream( const rtl::OUString& objectURL );
+
+ //sal_Int32 getFastPropertyIndex(sal_Int32 nHandle) const;
+
+ /*
+ * For signature generation
+ */
+ rtl::OUString createId();
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener > prepareSignatureToWrite(
+ InternalSignatureInformation& signatureInfo );
+
+ /*
+ * For signature verification
+ */
+ void addSignature();
+ void addReference( const rtl::OUString& ouUri);
+ void addStreamReference(
+ const rtl::OUString& ouUri,
+ bool isBinary );
+ void setReferenceCount() const;
+
+ void setX509IssuerName( rtl::OUString& ouX509IssuerName );
+ void setX509SerialNumber( rtl::OUString& ouX509SerialNumber );
+ void setX509Certificate( rtl::OUString& ouX509Certificate );
+ void setSignatureValue( rtl::OUString& ouSignatureValue );
+ void setDigestValue( rtl::OUString& ouDigestValue );
+ void setDate( rtl::OUString& ouDate );
+ void setTime( rtl::OUString& ouTime );
+
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XReferenceResolvedListener > prepareSignatureToRead(
+ sal_Int32 nSecurityId );
+
+public:
+ XSecController();
+ ~XSecController();
+
+ /*
+ * Common methods
+ */
+ void setFactory( const com::sun::star::uno::Reference<
+ com::sun::star::lang::XMultiServiceFactory>& rxMSF);
+#if 0
+ void setSignatureCreationResultListener( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureCreationResultListener >& xSignatureCreationResultListener);
+ void setSignatureVerifyResultListener( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener >& xSignatureVerifyResultListener);
+#endif
+
+ sal_Int32 getNewSecurityId( );
+
+ void startMission( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XUriBinding >& xUriBinding,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSecurityContext >& xSecurityContext );
+
+ void setSAXChainConnector(
+ const com::sun::star::uno::Reference<
+ com::sun::star::lang::XInitialization >& xInitialization,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XElementStackKeeper >& xElementStackKeeper);
+
+ void setSAXChainConnector(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XParser >& xParser,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::sax::XElementStackKeeper >& xElementStackKeeper);
+
+ void clearSAXChainConnector();
+ void endMission();
+ const char* getErrorMessage();
+ bool getSignatureInfor( sal_Int32 nSecurityId, SignatureInformation& signatureInfor );
+ SignatureInformations getSignatureInformations();
+
+ void exportSignature(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler,
+ const SignatureInformation& signatureInfo );
+
+
+ /*
+ * For signature generation
+ */
+ void collectToSign( sal_Int32 securityId, const rtl::OUString& referenceId );
+ void signAStream( sal_Int32 securityId, const rtl::OUString& uri, const rtl::OUString& objectURL, sal_Bool isBinary);
+
+ void setX509Certificate(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouX509IssuerName,
+ const rtl::OUString& ouX509SerialNumber);
+
+ void setDateTime(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouDate,
+ const rtl::OUString& ouTime);
+
+ bool WriteSignatue(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler );
+
+ /*
+ * For signature verification
+ */
+ void collectToVerify( const rtl::OUString& referenceId );
+ void addSignature( sal_Int32 nSignatureId );
+ com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > createSignatureReader();
+ void releaseSignatureReader();
+
+public:
+ /* Interface methods */
+
+ /*
+ * XSecurityController
+ *
+ * no method in XSecurityController interface
+ */
+
+ /*
+ * XFastPropertySet
+ */
+ /*
+ virtual void SAL_CALL setFastPropertyValue(
+ sal_Int32 nHandle,
+ const com::sun::star::uno::Any& aValue )
+ throw (
+ com::sun::star::beans::UnknownPropertyException,
+ com::sun::star::beans::PropertyVetoException,
+ com::sun::star::lang::IllegalArgumentException,
+ com::sun::star::lang::WrappedTargetException,
+ com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Any SAL_CALL getFastPropertyValue(
+ sal_Int32 nHandle )
+ throw (
+ com::sun::star::beans::UnknownPropertyException,
+ com::sun::star::lang::WrappedTargetException,
+ com::sun::star::uno::RuntimeException);
+ */
+
+ /*
+ * XSAXEventKeeperStatusChangeListener
+ */
+ virtual void SAL_CALL blockingStatusChanged( sal_Bool isBlocking )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL collectionStatusChanged(
+ sal_Bool isInsideCollectedElement )
+ throw (com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL bufferStatusChanged( sal_Bool isBufferEmpty )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /*
+ * XSignatureCreationResultListener
+ */
+ virtual void SAL_CALL signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureCreationResult nResult )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /*
+ * XSignatureVerifyResultListener
+ */
+ virtual void SAL_CALL signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::sax::SignatureVerifyResult nResult )
+ throw (com::sun::star::uno::RuntimeException);
+};
+
+#endif
+
diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx
new file mode 100644
index 000000000000..8ad5a7f747cd
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecparser.cxx
@@ -0,0 +1,353 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecparser.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 "xsecparser.hxx"
+
+#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
+#include <tools/debug.hxx>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssxs = com::sun::star::xml::sax;
+
+#define RTL_ASCII_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_ASCII_US
+
+XSecParser::XSecParser(
+ XSecController* pXSecController,
+ const cssu::Reference< cssxs::XDocumentHandler >& xNextHandler )
+ : m_pXSecController(pXSecController),
+ m_xNextHandler(xNextHandler),
+ m_bReferenceUnresolved(false)
+{
+}
+
+rtl::OUString XSecParser::getIdAttr(const cssu::Reference< cssxs::XAttributeList >& xAttribs )
+{
+ rtl::OUString ouIdAttr = xAttribs->getValueByName(
+ rtl::OUString(RTL_ASCII_USTRINGPARAM("id")));
+
+ if (ouIdAttr == NULL)
+ {
+ ouIdAttr = xAttribs->getValueByName(
+ rtl::OUString(RTL_ASCII_USTRINGPARAM("Id")));
+ }
+
+ return ouIdAttr;
+}
+
+/*
+ * XDocumentHandler
+ */
+void SAL_CALL XSecParser::startDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ m_bInX509IssuerName = false;
+ m_bInX509SerialNumber = false;
+ m_bInX509Certificate = false;
+ m_bInSignatureValue = false;
+ m_bInDigestValue = false;
+ m_bInDate = false;
+ m_bInTime = false;
+
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->startDocument();
+ }
+}
+
+void SAL_CALL XSecParser::endDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->endDocument();
+ }
+}
+
+void SAL_CALL XSecParser::startElement(
+ const rtl::OUString& aName,
+ const cssu::Reference< cssxs::XAttributeList >& xAttribs )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ rtl::OUString ouIdAttr = getIdAttr(xAttribs);
+ if (ouIdAttr != NULL)
+ {
+ m_pXSecController->collectToVerify( ouIdAttr );
+ }
+
+ if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_SIGNATURE)) )
+ {
+ m_pXSecController->addSignature();
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_REFERENCE)) )
+ {
+ rtl::OUString ouUri = xAttribs->getValueByName(rtl::OUString(RTL_ASCII_USTRINGPARAM(ATTR_URI)));
+ DBG_ASSERT( ouUri != NULL, "URI == NULL" );
+
+ if (0 == ouUri.compareTo(rtl::OUString(RTL_ASCII_USTRINGPARAM(CHAR_FRAGMENT)),1))
+ {
+ /*
+ * remove the first character '#' from the attribute value
+ */
+ m_pXSecController->addReference( ouUri.copy(1) );
+ }
+ else
+ {
+ /*
+ * remember the uri
+ */
+ m_currentReferenceURI = ouUri;
+ m_bReferenceUnresolved = true;
+ }
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_TRANSFORM)))
+ {
+ if ( m_bReferenceUnresolved )
+ {
+ rtl::OUString ouAlgorithm = xAttribs->getValueByName(rtl::OUString(RTL_ASCII_USTRINGPARAM(ATTR_ALGORITHM)));
+
+ if (ouAlgorithm != NULL && ouAlgorithm == rtl::OUString(RTL_ASCII_USTRINGPARAM(ALGO_C14N)))
+ /*
+ * a xml stream
+ */
+ {
+ m_pXSecController->addStreamReference( m_currentReferenceURI, sal_False);
+ m_bReferenceUnresolved = false;
+ }
+ }
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509ISSUERNAME)))
+ {
+ m_ouX509IssuerName = rtl::OUString::createFromAscii("");
+ m_bInX509IssuerName = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509SERIALNUMBER)))
+ {
+ m_ouX509SerialNumber = rtl::OUString::createFromAscii("");
+ m_bInX509SerialNumber = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509CERTIFICATE)))
+ {
+ m_ouX509Certificate = rtl::OUString::createFromAscii("");
+ m_bInX509Certificate = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_SIGNATUREVALUE)))
+ {
+ m_ouSignatureValue = rtl::OUString::createFromAscii("");
+ m_bInSignatureValue = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_DIGESTVALUE)))
+ {
+ m_ouDigestValue = rtl::OUString::createFromAscii("");
+ m_bInDigestValue = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_DATE)))
+ {
+ m_ouDate = rtl::OUString::createFromAscii("");
+ m_bInDate = true;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_TIME)))
+ {
+ m_ouTime = rtl::OUString::createFromAscii("");
+ m_bInTime = true;
+ }
+
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->startElement(aName, xAttribs);
+ }
+}
+
+void SAL_CALL XSecParser::endElement( const rtl::OUString& aName )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_DIGESTVALUE)))
+ {
+ m_bInDigestValue = false;
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_REFERENCE)) )
+ {
+ if ( m_bReferenceUnresolved )
+ /*
+ * it must be a octet stream
+ */
+ {
+ m_pXSecController->addStreamReference( m_currentReferenceURI, sal_True);
+ m_bReferenceUnresolved = false;
+ }
+
+ m_pXSecController->setDigestValue( m_ouDigestValue );
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_SIGNEDINFO)) )
+ {
+ m_pXSecController->setReferenceCount();
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_SIGNATUREVALUE)) )
+ {
+ m_pXSecController->setSignatureValue( m_ouSignatureValue );
+ m_bInSignatureValue = false;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509ISSUERNAME)))
+ {
+ m_pXSecController->setX509IssuerName( m_ouX509IssuerName );
+ m_bInX509IssuerName = false;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509SERIALNUMBER)))
+ {
+ m_pXSecController->setX509SerialNumber( m_ouX509SerialNumber );
+ m_bInX509SerialNumber = false;
+ }
+ else if (aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_X509CERTIFICATE)))
+ {
+ m_pXSecController->setX509Certificate( m_ouX509Certificate );
+ m_bInX509Certificate = false;
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_DATE)) )
+ {
+ m_pXSecController->setDate( m_ouDate );
+ m_bInDate = false;
+ }
+ else if ( aName == rtl::OUString(RTL_ASCII_USTRINGPARAM(TAG_TIME)) )
+ {
+ m_pXSecController->setTime( m_ouTime );
+ m_bInTime = false;
+ }
+
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->endElement(aName);
+ }
+}
+
+void SAL_CALL XSecParser::characters( const rtl::OUString& aChars )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_bInX509IssuerName)
+ {
+ m_ouX509IssuerName += aChars;
+ }
+ else if (m_bInX509SerialNumber)
+ {
+ m_ouX509SerialNumber += aChars;
+ }
+ else if (m_bInX509Certificate)
+ {
+ m_ouX509Certificate += aChars;
+ }
+ else if (m_bInSignatureValue)
+ {
+ m_ouSignatureValue += aChars;
+ }
+ else if (m_bInDigestValue)
+ {
+ m_ouDigestValue += aChars;
+ }
+ else if (m_bInDate)
+ {
+ m_ouDate += aChars;
+ }
+ else if (m_bInTime)
+ {
+ m_ouTime += aChars;
+ }
+
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->characters(aChars);
+ }
+}
+
+void SAL_CALL XSecParser::ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->ignorableWhitespace( aWhitespaces );
+ }
+}
+
+void SAL_CALL XSecParser::processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->processingInstruction(aTarget, aData);
+ }
+}
+
+void SAL_CALL XSecParser::setDocumentLocator( const cssu::Reference< cssxs::XLocator >& xLocator )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_xNextHandler.is())
+ {
+ m_xNextHandler->setDocumentLocator( xLocator );
+ }
+}
+
+/*
+ * XInitialization
+ */
+void SAL_CALL XSecParser::initialize(
+ const cssu::Sequence< cssu::Any >& aArguments )
+ throw(cssu::Exception, cssu::RuntimeException)
+{
+ aArguments[0] >>= m_xNextHandler;
+}
diff --git a/xmlsecurity/source/helper/xsecparser.hxx b/xmlsecurity/source/helper/xsecparser.hxx
new file mode 100644
index 000000000000..da2b765a7ad6
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecparser.hxx
@@ -0,0 +1,199 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecparser.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 _XSEC_CTL_PARSER_HXX
+#define _XSEC_CTL_PARSER_HXX
+
+#include <xsecctl.hxx>
+
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+#include <cppuhelper/implbase2.hxx>
+
+class XSecParser: public cppu::WeakImplHelper2
+<
+ com::sun::star::xml::sax::XDocumentHandler,
+ com::sun::star::lang::XInitialization
+>
+/****** XSecController.hxx/CLASS XSecParser ***********************************
+ *
+ * NAME
+ * XSecParser -- a SAX parser that can detect security elements
+ *
+ * FUNCTION
+ * The XSecParser object is connected on the SAX chain and detects
+ * security elements in the SAX event stream, then notifies
+ * the XSecController.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XDocumentHandler, XInitialization
+ *
+ * NOTES
+ * This class is used when importing a document.
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ friend class XSecController;
+private:
+ /*
+ * the following members are used to reserve the signature information,
+ * including X509IssuerName, X509SerialNumber, and X509Certificate,etc.
+ */
+ rtl::OUString m_ouX509IssuerName;
+ rtl::OUString m_ouX509SerialNumber;
+ rtl::OUString m_ouX509Certificate;
+ rtl::OUString m_ouDigestValue;
+ rtl::OUString m_ouSignatureValue;
+ rtl::OUString m_ouDate;
+ rtl::OUString m_ouTime;
+
+ /*
+ * whether inside a particular element
+ */
+ bool m_bInX509IssuerName;
+ bool m_bInX509SerialNumber;
+ bool m_bInX509Certificate;
+ bool m_bInDigestValue;
+ bool m_bInSignatureValue;
+ bool m_bInDate;
+ bool m_bInTime;
+
+ /*
+ * the XSecController collaborating with XSecParser
+ */
+ XSecController* m_pXSecController;
+
+ /*
+ * the next XDocumentHandler on the SAX chain
+ */
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
+
+ /*
+ * this string is used to remember the current handled reference's URI,
+ *
+ * because it can be decided whether a stream reference is xml based or binary based
+ * only after the Transforms element is read in, so we have to reserve the reference's
+ * URI when the startElement event is met.
+ */
+ rtl::OUString m_currentReferenceURI;
+ bool m_bReferenceUnresolved;
+
+private:
+ rtl::OUString getIdAttr(const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XAttributeList >& xAttribs );
+
+public:
+ XSecParser( XSecController* pXSecController,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xNextHandler );
+ ~XSecParser(){};
+
+ /*
+ * 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);
+
+ /*
+ * 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);
+};
+
+#endif
+
diff --git a/xmlsecurity/source/helper/xsecsign.cxx b/xmlsecurity/source/helper/xsecsign.cxx
new file mode 100644
index 000000000000..8b5bfaa1653e
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecsign.cxx
@@ -0,0 +1,394 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecsign.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 <xsecctl.hxx>
+
+#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
+#include <tools/debug.hxx>
+#endif
+
+#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
+#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#include <com/sun/star/xml/crypto/sax/XBlockerMonitor.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureCreationResultBroadcaster.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#include <stdio.h>
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxs = com::sun::star::xml::sax;
+
+/* xml security framework components */
+#define SIGNATURECREATOR_COMPONENT "com.sun.star.xml.crypto.sax.SignatureCreator"
+
+/* protected: for signature generation */
+rtl::OUString XSecController::createId()
+{
+ cssu::Sequence< sal_Int8 > aSeq( 16 );
+ rtl_createUuid ((sal_uInt8 *)aSeq.getArray(), 0, sal_True);
+
+ char str[68]="ID_";
+ int length = 3;
+ for (int i=0; i<16; ++i)
+ {
+ length += sprintf(str+length, "%04x", (unsigned char)aSeq[i]);
+ }
+
+ return rtl::OUString::createFromAscii(str);
+}
+
+cssu::Reference< cssxc::sax::XReferenceResolvedListener > XSecController::prepareSignatureToWrite(
+ InternalSignatureInformation& internalSignatureInfor )
+{
+ sal_Int32 nSecurityId = internalSignatureInfor.signatureInfor.nSecurityId;
+ SignatureReferenceInformations& vReferenceInfors = internalSignatureInfor.signatureInfor.vSignatureReferenceInfors;
+
+ sal_Int32 nIdOfSignatureElementCollector;
+ cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener;
+
+ nIdOfSignatureElementCollector =
+ m_xSAXEventKeeper->addSecurityElementCollector( cssxc::sax::ElementMarkPriority_PRI_AFTERMODIFY, sal_True );
+
+ m_xSAXEventKeeper->setSecurityId(nIdOfSignatureElementCollector, nSecurityId);
+
+ /*
+ * create a SignatureCreator
+ */
+ xReferenceResolvedListener = cssu::Reference< cssxc::sax::XReferenceResolvedListener >(
+ mxMSF->createInstance(
+ rtl::OUString::createFromAscii(SIGNATURECREATOR_COMPONENT)),
+ cssu::UNO_QUERY);
+
+ cssu::Reference<cssl::XInitialization> xInitialization(xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ cssu::Sequence<cssu::Any> args(5);
+ args[0] = cssu::makeAny(rtl::OUString::valueOf(nSecurityId));
+ args[1] = cssu::makeAny(m_xSAXEventKeeper);
+ args[2] = cssu::makeAny(rtl::OUString::valueOf(nIdOfSignatureElementCollector));
+ args[3] = cssu::makeAny(m_xSecurityContext);
+ args[4] = cssu::makeAny(m_xXMLSignature);
+ xInitialization->initialize(args);
+
+ sal_Int32 nBlockerId = m_xSAXEventKeeper->addBlocker();
+ m_xSAXEventKeeper->setSecurityId(nBlockerId, nSecurityId);
+
+ cssu::Reference<cssxc::sax::XBlockerMonitor> xBlockerMonitor(xReferenceResolvedListener, cssu::UNO_QUERY);
+ xBlockerMonitor->setBlockerId(nBlockerId);
+
+ cssu::Reference< cssxc::sax::XSignatureCreationResultBroadcaster >
+ xSignatureCreationResultBroadcaster(xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ xSignatureCreationResultBroadcaster->addSignatureCreationResultListener( this );
+
+ cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster>
+ xReferenceResolvedBroadcaster
+ (m_xSAXEventKeeper,
+ cssu::UNO_QUERY);
+
+ xReferenceResolvedBroadcaster->addReferenceResolvedListener(
+ nIdOfSignatureElementCollector,
+ xReferenceResolvedListener);
+
+ cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
+ (xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ int i;
+ int size = vReferenceInfors.size();
+ sal_Int32 nReferenceCount = 0;
+
+ for(i=0; i<size; ++i)
+ {
+ sal_Int32 keeperId = internalSignatureInfor.vKeeperIds[i];
+
+ if ( keeperId != -1)
+ {
+ m_xSAXEventKeeper->setSecurityId(keeperId, nSecurityId);
+ xReferenceResolvedBroadcaster->addReferenceResolvedListener( keeperId, xReferenceResolvedListener);
+ xReferenceCollector->setReferenceId( keeperId );
+ nReferenceCount++;
+ }
+ }
+
+ xReferenceCollector->setReferenceCount( nReferenceCount );
+
+ /*
+ * adds all URI binding
+ */
+ cssu::Reference<cssxc::XUriBinding> xUriBinding
+ (xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ for(i=0; i<size; ++i)
+ {
+ const SignatureReferenceInformation& refInfor = vReferenceInfors[i];
+
+ cssu::Reference< com::sun::star::io::XInputStream > xInputStream
+ = getObjectInputStream( refInfor.ouURI );
+
+ if (xInputStream.is())
+ {
+ xUriBinding->setUriBinding(refInfor.ouURI,xInputStream);
+ }
+ }
+
+ cssu::Reference<cssxc::sax::XKeyCollector> keyCollector (xReferenceResolvedListener, cssu::UNO_QUERY);
+ keyCollector->setKeyId(0);
+
+ if (internalSignatureInfor.signatureInfor.ouDate.getLength()>0 ||internalSignatureInfor.signatureInfor.ouTime.getLength()>0)
+ /*
+ * add a reference to datatime property, this reference is transparent to the xmlsecurity
+ * framework
+ */
+ {
+ internalSignatureInfor.signatureInfor.ouSignatureId = createId();
+ internalSignatureInfor.signatureInfor.ouPropertyId = createId();
+ internalSignatureInfor.addReference(1, internalSignatureInfor.signatureInfor.ouPropertyId, -1 );
+ size++;
+ }
+
+ /*
+ * replace both digestValues and signatueValue to " "
+ */
+ for(i=0; i<size; ++i)
+ {
+ SignatureReferenceInformation& refInfor = vReferenceInfors[i];
+ refInfor.ouDigestValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_BLANK));
+ }
+
+ internalSignatureInfor.signatureInfor.ouSignatureValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_BLANK));
+
+ return xReferenceResolvedListener;
+}
+
+/* public: for signature generation */
+void XSecController::collectToSign( sal_Int32 securityId, const rtl::OUString& referenceId )
+{
+ /* DBG_ASSERT( m_xSAXEventKeeper.is(), "the SAXEventKeeper is NULL" ); */
+
+ chainOn(true);
+
+ if ( m_nStatusOfSecurityComponents == INITIALIZED )
+ /*
+ * if all security components are ready, add a signature.
+ */
+ {
+ sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector(
+ cssxc::sax::ElementMarkPriority_PRI_AFTERMODIFY, sal_False);
+
+ int index = findSignatureInfor( securityId );
+
+ if ( index == -1 )
+ {
+ InternalSignatureInformation isi(securityId, NULL);
+ isi.addReference(1, referenceId, nKeeperId );
+ m_vInternalSignatureInformations.push_back( isi );
+ }
+ else
+ {
+ m_vInternalSignatureInformations[index].addReference(1, referenceId, nKeeperId );
+ }
+ }
+}
+
+void XSecController::signAStream( sal_Int32 securityId, const rtl::OUString& uri, const rtl::OUString& objectURL, sal_Bool isBinary)
+{
+ sal_Int32 type = ((isBinary==sal_True)?2:3);
+
+ int index = findSignatureInfor( securityId );
+
+ if (index == -1)
+ {
+ InternalSignatureInformation isi(securityId, NULL);
+ isi.addReference(type, uri, -1);
+ m_vInternalSignatureInformations.push_back( isi );
+ }
+ else
+ {
+ m_vInternalSignatureInformations[index].addReference(type, uri, -1);
+ }
+}
+
+void XSecController::setX509Certificate(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouX509IssuerName,
+ const rtl::OUString& ouX509SerialNumber)
+{
+ int index = findSignatureInfor( nSecurityId );
+
+ if ( index == -1 )
+ {
+ InternalSignatureInformation isi(nSecurityId, NULL);
+ isi.signatureInfor.ouX509IssuerName = ouX509IssuerName;
+ isi.signatureInfor.ouX509SerialNumber = ouX509SerialNumber;
+ m_vInternalSignatureInformations.push_back( isi );
+ }
+ else
+ {
+ SignatureInformation &si
+ = m_vInternalSignatureInformations[index].signatureInfor;
+ si.ouX509IssuerName = ouX509IssuerName;
+ si.ouX509SerialNumber = ouX509SerialNumber;
+ }
+}
+
+void XSecController::setDateTime(
+ sal_Int32 nSecurityId,
+ const rtl::OUString& ouDate,
+ const rtl::OUString& ouTime)
+{
+ int index = findSignatureInfor( nSecurityId );
+
+ if ( index == -1 )
+ {
+ InternalSignatureInformation isi(nSecurityId, NULL);
+ isi.signatureInfor.ouDate = ouDate;
+ isi.signatureInfor.ouTime = ouTime;
+ m_vInternalSignatureInformations.push_back( isi );
+ }
+ else
+ {
+ SignatureInformation &si
+ = m_vInternalSignatureInformations[index].signatureInfor;
+ si.ouDate = ouDate;
+ si.ouTime = ouTime;
+ }
+}
+
+bool XSecController::WriteSignatue(
+ const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler )
+{
+ bool rc = false;
+
+ DBG_ASSERT( xDocumentHandler.is(), "I really need a document handler!" );
+
+ /*
+ * chain the SAXEventKeeper to the SAX chain
+ */
+ chainOn(true);
+
+ if ( m_nStatusOfSecurityComponents == INITIALIZED )
+ /*
+ * if all security components are ready, add the signature
+ * stream.
+ */
+ {
+ m_bIsSAXEventKeeperSticky = true;
+ m_xSAXEventKeeper->setNextHandler(xDocumentHandler);
+
+ try
+ {
+ /*
+ * export the signature template
+ */
+ cssu::Reference<cssxs::XDocumentHandler> xSEKHandler( m_xSAXEventKeeper,cssu::UNO_QUERY);
+
+ int i;
+ int sigNum = m_vInternalSignatureInformations.size();
+
+ for (i=0; i<sigNum; ++i)
+ {
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[i];
+
+ /*
+ * prepare the signature creator
+ */
+ isi.xReferenceResolvedListener
+ = prepareSignatureToWrite( isi );
+
+ exportSignature( xSEKHandler, isi.signatureInfor );
+ }
+
+ m_bIsSAXEventKeeperSticky = false;
+ chainOff();
+
+ rc = true;
+ }
+ catch( cssxs::SAXException& )
+ {
+ m_pErrorMessage = ERROR_SAXEXCEPTIONDURINGCREATION;
+ }
+ catch( com::sun::star::io::IOException& )
+ {
+ m_pErrorMessage = ERROR_IOEXCEPTIONDURINGCREATION;
+ }
+ catch( cssu::Exception& )
+ {
+ m_pErrorMessage = ERROR_EXCEPTIONDURINGCREATION;
+ }
+
+ m_xSAXEventKeeper->setNextHandler( NULL );
+ m_bIsSAXEventKeeperSticky = false;
+ }
+ else
+ {
+ m_pErrorMessage = ERROR_CANNOTCREATEXMLSECURITYCOMPONENT;
+ }
+
+ return rc;
+}
+
diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx
new file mode 100644
index 000000000000..9faf78c864c0
--- /dev/null
+++ b/xmlsecurity/source/helper/xsecverify.cxx
@@ -0,0 +1,349 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsecverify.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 <xsecctl.hxx>
+#include "xsecparser.hxx"
+
+#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
+#include <tools/debug.hxx>
+#endif
+
+#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
+#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
+#include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
+#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxs = com::sun::star::xml::sax;
+
+/* xml security framework components */
+#define SIGNATUREVERIFIER_COMPONENT "com.sun.star.xml.crypto.sax.SignatureVerifier"
+
+/* protected: for signature verify */
+cssu::Reference< cssxc::sax::XReferenceResolvedListener > XSecController::prepareSignatureToRead(
+ sal_Int32 nSecurityId)
+{
+ if ( m_nStatusOfSecurityComponents != INITIALIZED )
+ {
+ return NULL;
+ }
+
+ sal_Int32 nIdOfSignatureElementCollector;
+ cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener;
+
+ nIdOfSignatureElementCollector =
+ m_xSAXEventKeeper->addSecurityElementCollector( cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY, sal_False);
+
+ m_xSAXEventKeeper->setSecurityId(nIdOfSignatureElementCollector, nSecurityId);
+
+ /*
+ * create a SignatureVerifier
+ */
+ xReferenceResolvedListener = cssu::Reference< cssxc::sax::XReferenceResolvedListener >(
+ mxMSF->createInstance(
+ rtl::OUString::createFromAscii( SIGNATUREVERIFIER_COMPONENT )),
+ cssu::UNO_QUERY);
+
+ cssu::Reference<cssl::XInitialization> xInitialization(xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ cssu::Sequence<cssu::Any> args(5);
+ args[0] = cssu::makeAny(rtl::OUString::valueOf(nSecurityId));
+ args[1] = cssu::makeAny(m_xSAXEventKeeper);
+ args[2] = cssu::makeAny(rtl::OUString::valueOf(nIdOfSignatureElementCollector));
+ args[3] = cssu::makeAny(m_xSecurityContext);
+ args[4] = cssu::makeAny(m_xXMLSignature);
+ xInitialization->initialize(args);
+
+ cssu::Reference< cssxc::sax::XSignatureVerifyResultBroadcaster >
+ signatureVerifyResultBroadcaster(xReferenceResolvedListener, cssu::UNO_QUERY);
+
+ signatureVerifyResultBroadcaster->addSignatureVerifyResultListener( this );
+
+ cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> xReferenceResolvedBroadcaster
+ (m_xSAXEventKeeper,
+ cssu::UNO_QUERY);
+
+ xReferenceResolvedBroadcaster->addReferenceResolvedListener(
+ nIdOfSignatureElementCollector,
+ xReferenceResolvedListener);
+
+ cssu::Reference<cssxc::sax::XKeyCollector> keyCollector (xReferenceResolvedListener, cssu::UNO_QUERY);
+ keyCollector->setKeyId(0);
+
+ return xReferenceResolvedListener;
+}
+
+void XSecController::addSignature()
+{
+ cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener = NULL;
+ sal_Int32 nSignatureId = 0;
+
+
+ if (m_bVerifyCurrentSignature)
+ {
+ chainOn(true);
+ xReferenceResolvedListener = prepareSignatureToRead( m_nReservedSignatureId );
+ m_bVerifyCurrentSignature = false;
+ nSignatureId = m_nReservedSignatureId;
+ }
+
+ InternalSignatureInformation isi( nSignatureId, xReferenceResolvedListener );
+ m_vInternalSignatureInformations.push_back( isi );
+}
+
+void XSecController::addReference( const rtl::OUString& ouUri)
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.addReference(1,ouUri, -1 );
+}
+
+void XSecController::addStreamReference(
+ const rtl::OUString& ouUri,
+ bool isBinary )
+{
+ sal_Int32 type = (isBinary?2:3);
+
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+
+ if ( isi.xReferenceResolvedListener.is() )
+ {
+ /*
+ * get the input stream
+ */
+ cssu::Reference< com::sun::star::io::XInputStream > xObjectInputStream
+ = getObjectInputStream( ouUri );
+
+ if ( xObjectInputStream.is() )
+ {
+ cssu::Reference<cssxc::XUriBinding> xUriBinding
+ (isi.xReferenceResolvedListener, cssu::UNO_QUERY);
+ xUriBinding->setUriBinding(ouUri, xObjectInputStream);
+ }
+ }
+
+ isi.addReference(type, ouUri, -1);
+}
+
+void XSecController::setReferenceCount() const
+{
+ const InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+
+ if ( isi.xReferenceResolvedListener.is() )
+ {
+ const SignatureReferenceInformations &refInfors = isi.signatureInfor.vSignatureReferenceInfors;
+
+ int refNum = refInfors.size();
+ sal_Int32 referenceCount = 0;
+
+ for(int i=0 ; i<refNum; ++i)
+ {
+ if (refInfors[i].nType == 1 )
+ /*
+ * same-document reference
+ */
+ {
+ referenceCount++;
+ }
+ }
+
+ cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
+ (isi.xReferenceResolvedListener, cssu::UNO_QUERY);
+ xReferenceCollector->setReferenceCount( referenceCount );
+ }
+}
+
+void XSecController::setX509IssuerName( rtl::OUString& ouX509IssuerName )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouX509IssuerName = ouX509IssuerName;
+}
+
+void XSecController::setX509SerialNumber( rtl::OUString& ouX509SerialNumber )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouX509SerialNumber = ouX509SerialNumber;
+}
+
+void XSecController::setX509Certificate( rtl::OUString& ouX509Certificate )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouX509Certificate = ouX509Certificate;
+}
+
+void XSecController::setSignatureValue( rtl::OUString& ouSignatureValue )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouSignatureValue = ouSignatureValue;
+}
+
+void XSecController::setDigestValue( rtl::OUString& ouDigestValue )
+{
+ SignatureInformation &si = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1].signatureInfor;
+ SignatureReferenceInformation &reference = si.vSignatureReferenceInfors[si.vSignatureReferenceInfors.size()-1];
+ reference.ouDigestValue = ouDigestValue;
+}
+
+void XSecController::setDate( rtl::OUString& ouDate )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouDate = ouDate;
+}
+
+void XSecController::setTime( rtl::OUString& ouTime )
+{
+ InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
+ isi.signatureInfor.ouTime = ouTime;
+}
+
+/* public: for signature verify */
+void XSecController::collectToVerify( const rtl::OUString& referenceId )
+{
+ /* DBG_ASSERT( m_xSAXEventKeeper.is(), "the SAXEventKeeper is NULL" ); */
+
+ if ( m_nStatusOfSecurityComponents == INITIALIZED )
+ /*
+ * if all security components are ready, verify the signature.
+ */
+ {
+ bool bJustChainingOn = false;
+ cssu::Reference< cssxs::XDocumentHandler > xHandler = NULL;
+
+ int i,j;
+ int sigNum = m_vInternalSignatureInformations.size();
+
+ for (i=0; i<sigNum; ++i)
+ {
+ InternalSignatureInformation& isi = m_vInternalSignatureInformations[i];
+ SignatureReferenceInformations& vReferenceInfors = isi.signatureInfor.vSignatureReferenceInfors;
+ int refNum = vReferenceInfors.size();
+
+ for (j=0; j<refNum; ++j)
+ {
+ SignatureReferenceInformation &refInfor = vReferenceInfors[j];
+
+ if (refInfor.ouURI == referenceId)
+ {
+ if (chainOn(false))
+ {
+ bJustChainingOn = true;
+ xHandler = m_xSAXEventKeeper->setNextHandler(NULL);
+ }
+
+ sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector(
+ cssxc::sax::ElementMarkPriority_PRI_BEFOREMODIFY, sal_False );
+
+ cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> xReferenceResolvedBroadcaster
+ (m_xSAXEventKeeper,
+ cssu::UNO_QUERY );
+
+ cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
+ ( isi.xReferenceResolvedListener, cssu::UNO_QUERY );
+
+ m_xSAXEventKeeper->setSecurityId(nKeeperId, isi.signatureInfor.nSecurityId);
+ xReferenceResolvedBroadcaster->addReferenceResolvedListener( nKeeperId, isi.xReferenceResolvedListener);
+ xReferenceCollector->setReferenceId( nKeeperId );
+
+ isi.vKeeperIds[j] = nKeeperId;
+ break;
+ }
+ }
+ }
+
+ if ( bJustChainingOn )
+ {
+ cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(m_xSAXEventKeeper, cssu::UNO_QUERY);
+ if (m_xElementStackKeeper.is())
+ {
+ m_xElementStackKeeper->retrieve(xSEKHandler, sal_True);
+ }
+ m_xSAXEventKeeper->setNextHandler(xHandler);
+ }
+ }
+}
+
+void XSecController::addSignature( sal_Int32 nSignatureId )
+{
+ DBG_ASSERT( m_pXSecParser != NULL, "No XSecParser initialized" );
+
+ m_nReservedSignatureId = nSignatureId;
+ m_bVerifyCurrentSignature = true;
+}
+
+cssu::Reference< cssxs::XDocumentHandler > XSecController::createSignatureReader()
+{
+ m_pXSecParser = new XSecParser( this, NULL );
+ cssu::Reference< cssl::XInitialization > xInitialization = m_pXSecParser;
+
+ setSAXChainConnector(xInitialization, NULL, NULL);
+
+ return m_pXSecParser;
+}
+
+void XSecController::releaseSignatureReader()
+{
+ clearSAXChainConnector( );
+ m_pXSecParser = NULL;
+}
+
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 ;
+}
+
+}
+