1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <rtl/locale.h> 32*cdf0e10cSrcweir #include <osl/nlsupport.h> 33*cdf0e10cSrcweir #include <osl/process.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <util.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <stdio.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/security/KeyUsage.hpp> 41*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 42*cdf0e10cSrcweir #include <xmlsecurity/biginteger.hxx> 43*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 44*cdf0e10cSrcweir #include <unotools/streamhelper.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 47*cdf0e10cSrcweir #include <tools/string.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir namespace cssu = com::sun::star::uno; 50*cdf0e10cSrcweir namespace cssl = com::sun::star::lang; 51*cdf0e10cSrcweir namespace cssxc = com::sun::star::xml::crypto; 52*cdf0e10cSrcweir namespace cssi = com::sun::star::io; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** convert util::DateTime to ISO Date String */ 57*cdf0e10cSrcweir void convertDateTime( ::rtl::OUStringBuffer& rBuffer, 58*cdf0e10cSrcweir const com::sun::star::util::DateTime& rDateTime ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir String aString( String::CreateFromInt32( rDateTime.Year ) ); 61*cdf0e10cSrcweir aString += '-'; 62*cdf0e10cSrcweir if( rDateTime.Month < 10 ) 63*cdf0e10cSrcweir aString += '0'; 64*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.Month ); 65*cdf0e10cSrcweir aString += '-'; 66*cdf0e10cSrcweir if( rDateTime.Day < 10 ) 67*cdf0e10cSrcweir aString += '0'; 68*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.Day ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir if( rDateTime.Seconds != 0 || 71*cdf0e10cSrcweir rDateTime.Minutes != 0 || 72*cdf0e10cSrcweir rDateTime.Hours != 0 ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir aString += 'T'; 75*cdf0e10cSrcweir if( rDateTime.Hours < 10 ) 76*cdf0e10cSrcweir aString += '0'; 77*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.Hours ); 78*cdf0e10cSrcweir aString += ':'; 79*cdf0e10cSrcweir if( rDateTime.Minutes < 10 ) 80*cdf0e10cSrcweir aString += '0'; 81*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.Minutes ); 82*cdf0e10cSrcweir aString += ':'; 83*cdf0e10cSrcweir if( rDateTime.Seconds < 10 ) 84*cdf0e10cSrcweir aString += '0'; 85*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.Seconds ); 86*cdf0e10cSrcweir if ( rDateTime.HundredthSeconds > 0) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir aString += ','; 89*cdf0e10cSrcweir if (rDateTime.HundredthSeconds < 10) 90*cdf0e10cSrcweir aString += '0'; 91*cdf0e10cSrcweir aString += String::CreateFromInt32( rDateTime.HundredthSeconds ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir rBuffer.append( aString ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir ::rtl::OUString printHexString(cssu::Sequence< sal_Int8 > data) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir int length = data.getLength(); 101*cdf0e10cSrcweir ::rtl::OUString result; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir char number[4]; 104*cdf0e10cSrcweir for (int j=0; j<length; j++) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir sprintf(number, "%02X ", (unsigned char)data[j]); 107*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( number ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir return result; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir ::rtl::OUString getSignatureInformation( 115*cdf0e10cSrcweir const SignatureInformation& infor, 116*cdf0e10cSrcweir cssu::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& xSecurityEnvironment ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir char* status[50] = { 119*cdf0e10cSrcweir "STATUS_UNKNOWN", 120*cdf0e10cSrcweir "OPERATION_SUCCEEDED", 121*cdf0e10cSrcweir "RUNTIMEERROR_FAILED", 122*cdf0e10cSrcweir "ENGINE_FAILED", 123*cdf0e10cSrcweir "MALLOC_FAILED", 124*cdf0e10cSrcweir "STRDUP_FAILED", 125*cdf0e10cSrcweir "CRYPTO_FAILED", 126*cdf0e10cSrcweir "XML_FAILED", 127*cdf0e10cSrcweir "XSLT_FAILED", 128*cdf0e10cSrcweir "IO_FAILED", 129*cdf0e10cSrcweir "DISABLED", 130*cdf0e10cSrcweir "NOT_IMPLEMENTED", 131*cdf0e10cSrcweir "INVALID_SIZE", 132*cdf0e10cSrcweir "INVALID_DATA", 133*cdf0e10cSrcweir "INVALID_RESULT", 134*cdf0e10cSrcweir "INVALID_TYPE", 135*cdf0e10cSrcweir "INVALID_OPERATION", 136*cdf0e10cSrcweir "INVALID_STATUS", 137*cdf0e10cSrcweir "INVALID_FORMAT", 138*cdf0e10cSrcweir "DATA_NOT_MATCH", 139*cdf0e10cSrcweir "INVALID_NODE", 140*cdf0e10cSrcweir "INVALID_NODE_CONTENT", 141*cdf0e10cSrcweir "INVALID_NODE_ATTRIBUTE", 142*cdf0e10cSrcweir "MISSING_NODE_ATTRIBUTE", 143*cdf0e10cSrcweir "NODE_ALREADY_PRESENT", 144*cdf0e10cSrcweir "UNEXPECTED_NODE", 145*cdf0e10cSrcweir "NODE_NOT_FOUND", 146*cdf0e10cSrcweir "INVALID_TRANSFORM", 147*cdf0e10cSrcweir "INVALID_TRANSFORM_KEY", 148*cdf0e10cSrcweir "INVALID_URI_TYPE", 149*cdf0e10cSrcweir "TRANSFORM_SAME_DOCUMENT_REQUIRED", 150*cdf0e10cSrcweir "TRANSFORM_DISABLED", 151*cdf0e10cSrcweir "INVALID_KEY_DATA", 152*cdf0e10cSrcweir "KEY_DATA_NOT_FOUND", 153*cdf0e10cSrcweir "KEY_DATA_ALREADY_EXIST", 154*cdf0e10cSrcweir "INVALID_KEY_DATA_SIZE", 155*cdf0e10cSrcweir "KEY_NOT_FOUND", 156*cdf0e10cSrcweir "KEYDATA_DISABLED", 157*cdf0e10cSrcweir "MAX_RETRIEVALS_LEVEL", 158*cdf0e10cSrcweir "MAX_RETRIEVAL_TYPE_MISMATCH", 159*cdf0e10cSrcweir "MAX_ENCKEY_LEVEL", 160*cdf0e10cSrcweir "CERT_VERIFY_FAILED", 161*cdf0e10cSrcweir "CERT_NOT_FOUND", 162*cdf0e10cSrcweir "CERT_REVOKED", 163*cdf0e10cSrcweir "CERT_ISSUER_FAILED", 164*cdf0e10cSrcweir "CERT_NOT_YET_VALID", 165*cdf0e10cSrcweir "CERT_HAS_EXPIRED", 166*cdf0e10cSrcweir "DSIG_NO_REFERENCES", 167*cdf0e10cSrcweir "DSIG_INVALID_REFERENCE", 168*cdf0e10cSrcweir "ASSERTION"}; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir rtl::OUString result; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "Security Id : " ) 173*cdf0e10cSrcweir +rtl::OUString::valueOf(infor.nSecurityId) 174*cdf0e10cSrcweir +rtl::OUString::createFromAscii( "\n" ); 175*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "Status : [" ) 176*cdf0e10cSrcweir +rtl::OUString::valueOf((sal_Int32)(infor.nStatus)) 177*cdf0e10cSrcweir +rtl::OUString::createFromAscii( "] " ) 178*cdf0e10cSrcweir +rtl::OUString::createFromAscii(status[infor.nStatus]) 179*cdf0e10cSrcweir +rtl::OUString::createFromAscii( "\n" ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir const SignatureReferenceInformations& rInfors = infor.vSignatureReferenceInfors; 182*cdf0e10cSrcweir int i; 183*cdf0e10cSrcweir int size = rInfors.size(); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--References :\n" ); 186*cdf0e10cSrcweir for (i=0; i<size; i++) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "---URI : " ); 189*cdf0e10cSrcweir result += rInfors[i].ouURI; 190*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 191*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "---DigestValue : " ); 192*cdf0e10cSrcweir result += rInfors[i].ouDigestValue; 193*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if (infor.ouX509IssuerName.getLength()>0) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--X509IssuerName :\n" ); 199*cdf0e10cSrcweir result += infor.ouX509IssuerName; 200*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if (infor.ouX509SerialNumber.getLength()>0) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--X509SerialNumber :\n" ); 206*cdf0e10cSrcweir result += infor.ouX509SerialNumber; 207*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir if (infor.ouX509Certificate.getLength()>0) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--X509Certificate :\n" ); 213*cdf0e10cSrcweir result += infor.ouX509Certificate; 214*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir if (infor.ouSignatureValue.getLength()>0) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--SignatureValue :\n" ); 220*cdf0e10cSrcweir result += infor.ouSignatureValue; 221*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--Date :\n" ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir ::rtl::OUStringBuffer buffer; 227*cdf0e10cSrcweir convertDateTime( buffer, infor.stDateTime ); 228*cdf0e10cSrcweir result += buffer.makeStringAndClear(); 229*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if (infor.ouX509IssuerName.getLength()>0 && infor.ouX509SerialNumber.getLength()>0 && xSecurityEnvironment.is()) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "--Certificate Path :\n" ); 234*cdf0e10cSrcweir cssu::Reference< ::com::sun::star::security::XCertificate > xCert = xSecurityEnvironment->getCertificate( infor.ouX509IssuerName, numericStringToBigInteger(infor.ouX509SerialNumber) ); 235*cdf0e10cSrcweir cssu::Sequence < cssu::Reference< ::com::sun::star::security::XCertificate > > xCertPath; 236*cdf0e10cSrcweir if(! xCert.is() ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir fprintf(stdout , " xCert is NULL , so can not buildCertificatePath\n"); 239*cdf0e10cSrcweir return result ; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir else 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir xCertPath = xSecurityEnvironment->buildCertificatePath( xCert ) ; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir for( int i = 0; i < xCertPath.getLength(); i++ ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir result += xCertPath[i]->getSubjectName(); 249*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Subject public key algorithm : " ); 250*cdf0e10cSrcweir result += xCertPath[i]->getSubjectPublicKeyAlgorithm(); 251*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Signature algorithm : " ); 252*cdf0e10cSrcweir result += xCertPath[i]->getSignatureAlgorithm(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Subject public key value : " ); 255*cdf0e10cSrcweir cssu::Sequence< sal_Int8 > keyValue = xCertPath[i]->getSubjectPublicKeyValue(); 256*cdf0e10cSrcweir result += printHexString(keyValue); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Thumbprint (SHA1) : " ); 259*cdf0e10cSrcweir cssu::Sequence< sal_Int8 > SHA1Thumbprint = xCertPath[i]->getSHA1Thumbprint(); 260*cdf0e10cSrcweir result += printHexString(SHA1Thumbprint); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Thumbprint (MD5) : " ); 263*cdf0e10cSrcweir cssu::Sequence< sal_Int8 > MD5Thumbprint = xCertPath[i]->getMD5Thumbprint(); 264*cdf0e10cSrcweir result += printHexString(MD5Thumbprint); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n <<\n" ); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n Key Usage : " ); 270*cdf0e10cSrcweir sal_Int32 usage = xCert->getCertificateUsage(); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::DIGITAL_SIGNATURE) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "DIGITAL_SIGNATURE " ); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::NON_REPUDIATION) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "NON_REPUDIATION " ); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::KEY_ENCIPHERMENT) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "KEY_ENCIPHERMENT " ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::DATA_ENCIPHERMENT) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "DATA_ENCIPHERMENT " ); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::KEY_AGREEMENT) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "KEY_AGREEMENT " ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::KEY_CERT_SIGN) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "KEY_CERT_SIGN " ); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if (usage & ::com::sun::star::security::KeyUsage::CRL_SIGN) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "CRL_SIGN " ); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 311*cdf0e10cSrcweir return result; 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir ::rtl::OUString getSignatureInformations( 315*cdf0e10cSrcweir const SignatureInformations& SignatureInformations, 316*cdf0e10cSrcweir cssu::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir rtl::OUString result; 319*cdf0e10cSrcweir int i; 320*cdf0e10cSrcweir int size = SignatureInformations.size(); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir for (i=0; i<size; i++) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir const SignatureInformation& infor = SignatureInformations[i]; 325*cdf0e10cSrcweir result += getSignatureInformation( infor, xSecurityEnvironment ); 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir result += rtl::OUString::createFromAscii( "\n" ); 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir return result; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > 334*cdf0e10cSrcweir getCertificateFromEnvironment( ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment , sal_Bool nType) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir cssu::Sequence< cssu::Reference< ::com::sun::star::security::XCertificate > > xPersonalCerts ; 337*cdf0e10cSrcweir int length = 0; 338*cdf0e10cSrcweir int i; 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // add By CP 341*cdf0e10cSrcweir sal_uInt16 encoding ; 342*cdf0e10cSrcweir rtl_Locale *pLocale = NULL ; 343*cdf0e10cSrcweir osl_getProcessLocale( &pLocale ) ; 344*cdf0e10cSrcweir encoding = osl_getTextEncodingFromLocale( pLocale ) ; 345*cdf0e10cSrcweir // CP end 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir if( nType != sal_False ) 348*cdf0e10cSrcweir xPersonalCerts = xSecurityEnvironment->getPersonalCertificates() ; 349*cdf0e10cSrcweir else 350*cdf0e10cSrcweir return NULL; // not support then; 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir length = xPersonalCerts.getLength(); 353*cdf0e10cSrcweir if(length == 0) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir fprintf( stdout, "\nNo certificate found!\n" ) ; 356*cdf0e10cSrcweir return NULL; 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir fprintf( stdout, "\nSelect a certificate:\n" ) ; 360*cdf0e10cSrcweir for( i = 0; i < length; i ++ ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir rtl::OUString xxxIssuer; 363*cdf0e10cSrcweir rtl::OUString xxxSubject; 364*cdf0e10cSrcweir rtl::OString yyyIssuer; 365*cdf0e10cSrcweir rtl::OString yyySubject; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir xxxIssuer=xPersonalCerts[i]->getIssuerName(); 368*cdf0e10cSrcweir yyyIssuer=rtl::OUStringToOString( xxxIssuer, encoding ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir xxxSubject=xPersonalCerts[i]->getSubjectName(); 371*cdf0e10cSrcweir yyySubject=rtl::OUStringToOString( xxxSubject, encoding ); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir fprintf( stdout, "\n%d:\nsubject=[%s]\nissuer=[%s]\n", 374*cdf0e10cSrcweir i+1, 375*cdf0e10cSrcweir yyySubject.getStr(), 376*cdf0e10cSrcweir yyyIssuer.getStr()); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir int sel = QuerySelectNumber( 1, length ) -1; 380*cdf0e10cSrcweir return xPersonalCerts[sel] ; 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir void QueryPrintSignatureDetails( const SignatureInformations& SignatureInformations, ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > rSecEnv ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir char cShowDetails; 386*cdf0e10cSrcweir fprintf( stdout, "\nDisplay details (y/n) [y]?" ); 387*cdf0e10cSrcweir fflush( stdout ); 388*cdf0e10cSrcweir fscanf( stdin, "%c", &cShowDetails); 389*cdf0e10cSrcweir if ( cShowDetails == 'y' ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir rtl_Locale *pLocale = NULL ; 392*cdf0e10cSrcweir osl_getProcessLocale( &pLocale ) ; 393*cdf0e10cSrcweir sal_uInt16 encoding = osl_getTextEncodingFromLocale( pLocale ) ; 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir fprintf( stdout, "------------- Signature details START -------------\n" ); 396*cdf0e10cSrcweir fprintf( stdout, "%s", 397*cdf0e10cSrcweir rtl::OUStringToOString( 398*cdf0e10cSrcweir getSignatureInformations( SignatureInformations, rSecEnv), 399*cdf0e10cSrcweir encoding).getStr()); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir fprintf( stdout, "------------- Signature details END -------------\n" ); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir int QuerySelectNumber( int nMin, int nMax ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir fprintf( stdout, "\n" ) ; 408*cdf0e10cSrcweir int sel = 0; 409*cdf0e10cSrcweir do 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir fprintf( stdout, "\nSelect <%d-%d>:", nMin, nMax ) ; 412*cdf0e10cSrcweir fflush( stdout ); 413*cdf0e10cSrcweir fscanf( stdin, "%d", &sel ) ; 414*cdf0e10cSrcweir } while( ( sel < nMin ) || ( sel > nMax ) ); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir return sel; 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir long QueryVerifySignature() 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir char answer; 422*cdf0e10cSrcweir fprintf( stdout, "\nFound a signature - verify this one (y/n) [y]?" ); 423*cdf0e10cSrcweir fflush( stdout ); 424*cdf0e10cSrcweir fscanf( stdin, "%c", &answer); 425*cdf0e10cSrcweir return (answer == 'n')?0:1; 426*cdf0e10cSrcweir } 427