summaryrefslogtreecommitdiff
path: root/xmlsecurity/tools/demo/util.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'xmlsecurity/tools/demo/util.cxx')
-rw-r--r--xmlsecurity/tools/demo/util.cxx215
1 files changed, 215 insertions, 0 deletions
diff --git a/xmlsecurity/tools/demo/util.cxx b/xmlsecurity/tools/demo/util.cxx
new file mode 100644
index 000000000000..a73179805a5e
--- /dev/null
+++ b/xmlsecurity/tools/demo/util.cxx
@@ -0,0 +1,215 @@
+/*************************************************************************
+ *
+ * $RCSfile: util.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:30 $
+ *
+ * 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 "util.hxx"
+
+#include <com/sun/star/registry/XImplementationRegistration.hpp>
+#include <cppuhelper/bootstrap.hxx>
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+
+cssu::Reference< cssl::XMultiServiceFactory > serviceManager(
+ cssu::Reference< cssu::XComponentContext > &xContext,
+ rtl::OUString sUnoUrl,
+ rtl::OUString sRdbUrl )
+ throw( cssu::RuntimeException , cssu::Exception )
+{
+ cssu::Reference< cssl::XMultiComponentFactory > xLocalServiceManager = NULL ;
+ cssu::Reference< cssu::XComponentContext > xLocalComponentContext = NULL ;
+
+ cssu::Reference< ::com::sun::star::registry::XSimpleRegistry > xSimpleRegistry
+ = ::cppu::createSimpleRegistry();
+ OSL_ENSURE( xSimpleRegistry.is(),
+ "serviceManager - "
+ "Cannot create simple registry" ) ;
+
+ xSimpleRegistry->open(sRdbUrl, sal_True, sal_False);
+ OSL_ENSURE( xSimpleRegistry->isValid() ,
+ "serviceManager - "
+ "Cannot open xml security registry rdb" ) ;
+
+ xLocalComponentContext = ::cppu::bootstrap_InitialComponentContext( xSimpleRegistry ) ;
+ OSL_ENSURE( xLocalComponentContext.is() ,
+ "serviceManager - "
+ "Cannot create intial component context" ) ;
+
+ xLocalServiceManager = xLocalComponentContext->getServiceManager() ;
+ OSL_ENSURE( xLocalServiceManager.is() ,
+ "serviceManager - "
+ "Cannot create intial service manager" ) ;
+
+ xContext = xLocalComponentContext ;
+ return cssu::Reference< cssl::XMultiServiceFactory >(xLocalServiceManager, cssu::UNO_QUERY) ;
+}
+
+::rtl::OUString getSignatureInformation(
+ const SignatureInformation& infor,
+ cssu::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& xSecurityEnvironment )
+{
+ char* status[5]={"INIT", "CREATION_SUCCEED", "CREATION_FAIL", "VERIFY_SUCCEED", "VERIFY_FAIL"};
+
+ rtl::OUString result;
+
+ result += rtl::OUString::createFromAscii( "Security Id : " )
+ +rtl::OUString::valueOf(infor.nSecurityId)
+ +rtl::OUString::createFromAscii( "\n" );
+ result += rtl::OUString::createFromAscii( "Status : " )
+ +rtl::OUString::createFromAscii( status[infor.nStatus] )
+ +rtl::OUString::createFromAscii( "\n" );
+
+ const SignatureReferenceInformations& rInfors = infor.vSignatureReferenceInfors;
+ int i;
+ int size = rInfors.size();
+
+ result += rtl::OUString::createFromAscii( "--References :\n" );
+ for (i=0; i<size; i++)
+ {
+ result += rtl::OUString::createFromAscii( "---URI : " );
+ result += rInfors[i].ouURI;
+ result += rtl::OUString::createFromAscii( "\n" );
+ result += rtl::OUString::createFromAscii( "---DigestValue : " );
+ result += rInfors[i].ouDigestValue;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouX509IssuerName.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--X509IssuerName :\n" );
+ result += infor.ouX509IssuerName;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouX509SerialNumber.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--X509SerialNumber :\n" );
+ result += infor.ouX509SerialNumber;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouX509Certificate.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--X509Certificate :\n" );
+ result += infor.ouX509Certificate;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouSignatureValue.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--SignatureValue :\n" );
+ result += infor.ouSignatureValue;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouDate.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--Date :\n" );
+ result += infor.ouDate;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouTime.getLength()>0)
+ {
+ result += rtl::OUString::createFromAscii( "--Time :\n" );
+ result += infor.ouTime;
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ if (infor.ouX509IssuerName.getLength()>0 && infor.ouX509SerialNumber.getLength()>0 && xSecurityEnvironment.is())
+ {
+ result += rtl::OUString::createFromAscii( "--Certificate Path :\n" );
+ cssu::Reference< ::com::sun::star::security::XCertificate > xCert
+ = xSecurityEnvironment->getCertificate( infor.ouX509IssuerName, numericStringToBigInteger(infor.ouX509SerialNumber) );
+
+ cssu::Sequence < cssu::Reference< ::com::sun::star::security::XCertificate > > xCertPath
+ = xSecurityEnvironment->buildCertificatePath( xCert ) ;
+
+ for( int i = 0; i < xCertPath.getLength(); i++ )
+ {
+ result += xCertPath[i]->getSubjectName();
+ result += rtl::OUString::createFromAscii( " << " );
+ }
+
+ result += rtl::OUString::createFromAscii( "\n" );
+ }
+
+ result += rtl::OUString::createFromAscii( "\n" );
+ return result;
+}
+
+::rtl::OUString getSignatureInformations(
+ const SignatureInformations& SignatureInformations,
+ cssu::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& xSecurityEnvironment )
+{
+ rtl::OUString result;
+ int i;
+ int size = SignatureInformations.size();
+
+ for (i=0; i<size; i++)
+ {
+ const SignatureInformation& infor = SignatureInformations[i];
+ result += getSignatureInformation( infor, xSecurityEnvironment );
+ }
+
+ result += rtl::OUString::createFromAscii( "\n" );
+
+ return result;
+}