1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 
26 #include "precompiled_xmlsecurity.hxx"
27 
28 #include <documentdigitalsignatures.hxx>
29 #include <xmlsecurity/digitalsignaturesdialog.hxx>
30 #include <xmlsecurity/certificateviewer.hxx>
31 #include <xmlsecurity/macrosecurity.hxx>
32 #include <xmlsecurity/biginteger.hxx>
33 #include <xmlsecurity/global.hrc>
34 
35 #include <xmloff/xmluconv.hxx>
36 
37 #include <../dialogs/resourcemanager.hxx>
38 #include <com/sun/star/embed/XStorage.hpp>
39 #include <com/sun/star/embed/XTransactedObject.hpp>
40 #include <com/sun/star/embed/ElementModes.hpp>
41 #include <com/sun/star/ucb/XContent.hpp>
42 #include <com/sun/star/ucb/XContentProvider.hpp>
43 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
44 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
45 #include <com/sun/star/ucb/XCommandProcessor.hpp>
46 #include <com/sun/star/ucb/Command.hpp>
47 #include <tools/urlobj.hxx>
48 #include <vcl/msgbox.hxx>
49 #include <unotools/securityoptions.hxx>
50 #include <com/sun/star/security/CertificateValidity.hpp>
51 #include <com/sun/star/security/SerialNumberAdapter.hpp>
52 #include <ucbhelper/contentbroker.hxx>
53 #include <unotools/ucbhelper.hxx>
54 #include <comphelper/componentcontext.hxx>
55 #include "comphelper/documentconstants.hxx"
56 
57 #include "com/sun/star/lang/IllegalArgumentException.hpp"
58 
59 #include <stdio.h>
60 
61 
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::uno;
64 namespace css = ::com::sun::star;
65 
66 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
67 
DocumentDigitalSignatures(const Reference<XComponentContext> & rxCtx)68 DocumentDigitalSignatures::DocumentDigitalSignatures( const Reference< XComponentContext >& rxCtx ):
69     mxCtx(rxCtx),
70     m_sODFVersion(ODFVER_012_TEXT),
71     m_nArgumentsCount(0),
72     m_bHasDocumentSignature(false)
73 {
74 }
75 
initialize(const Sequence<Any> & aArguments)76 void DocumentDigitalSignatures::initialize( const Sequence< Any >& aArguments)
77 		throw (css::uno::Exception, css::uno::RuntimeException)
78 {
79     if (aArguments.getLength() == 0 || aArguments.getLength() > 2)
80         throw css::lang::IllegalArgumentException(
81         OUSTR("DocumentDigitalSignatures::initialize requires one or two arguments"),
82         Reference<XInterface>(static_cast<XInitialization*>(this), UNO_QUERY), 0);
83 
84     m_nArgumentsCount = aArguments.getLength();
85 
86     if (!(aArguments[0] >>= m_sODFVersion))
87         throw css::lang::IllegalArgumentException(
88         OUSTR("DocumentDigitalSignatures::initialize: the first arguments must be a string"),
89         Reference<XInterface>(static_cast<XInitialization*>(this), UNO_QUERY), 0);
90 
91     if (aArguments.getLength() == 2
92         && !(aArguments[1] >>= m_bHasDocumentSignature))
93         throw css::lang::IllegalArgumentException(
94         OUSTR("DocumentDigitalSignatures::initialize: the second arguments must be a bool"),
95         Reference<XInterface>(static_cast<XInitialization*>(this), UNO_QUERY), 1);
96 
97     //the Version is supported as of ODF1.2, so for and 1.1 document or older we will receive the
98     //an empty string. In this case we set it to ODFVER_010_TEXT. Then we can later check easily
99     //if initialize was called. Only then m_sODFVersion.getLength() is greater than 0
100     if (m_sODFVersion.getLength() == 0)
101         m_sODFVersion = ODFVER_010_TEXT;
102 }
103 
signDocumentContent(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XStream> & xSignStream)104 sal_Bool DocumentDigitalSignatures::signDocumentContent(
105     const Reference< css::embed::XStorage >& rxStorage,
106     const Reference< css::io::XStream >& xSignStream)
107         throw (RuntimeException)
108 {
109     OSL_ENSURE(m_sODFVersion.getLength(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
110     return ImplViewSignatures( rxStorage, xSignStream, SignatureModeDocumentContent, false );
111 }
112 
113 Sequence< css::security::DocumentSignatureInformation >
verifyDocumentContentSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)114 DocumentDigitalSignatures::verifyDocumentContentSignatures(
115     const Reference< css::embed::XStorage >& rxStorage,
116     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
117 {
118     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
119     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModeDocumentContent );
120 }
121 
showDocumentContentSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)122 void DocumentDigitalSignatures::showDocumentContentSignatures(
123     const Reference< css::embed::XStorage >& rxStorage,
124     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
125 {
126     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
127     ImplViewSignatures( rxStorage, xSignInStream, SignatureModeDocumentContent, true );
128 }
129 
getDocumentContentSignatureDefaultStreamName()130 ::rtl::OUString DocumentDigitalSignatures::getDocumentContentSignatureDefaultStreamName()
131     throw (css::uno::RuntimeException)
132 {
133 	return DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName();
134 }
135 
signScriptingContent(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XStream> & xSignStream)136 sal_Bool DocumentDigitalSignatures::signScriptingContent(
137     const Reference< css::embed::XStorage >& rxStorage,
138     const Reference< css::io::XStream >& xSignStream ) throw (RuntimeException)
139 {
140     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
141     OSL_ENSURE(m_nArgumentsCount == 2, "DocumentDigitalSignatures: Service was not initialized properly");
142     return ImplViewSignatures( rxStorage, xSignStream, SignatureModeMacros, false );
143 }
144 
145 Sequence< css::security::DocumentSignatureInformation >
verifyScriptingContentSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)146 DocumentDigitalSignatures::verifyScriptingContentSignatures(
147     const Reference< css::embed::XStorage >& rxStorage,
148     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
149 {
150     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
151     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModeMacros );
152 }
153 
showScriptingContentSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)154 void DocumentDigitalSignatures::showScriptingContentSignatures(
155     const Reference< css::embed::XStorage >& rxStorage,
156     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
157 {
158     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
159     ImplViewSignatures( rxStorage, xSignInStream, SignatureModeMacros, true );
160 }
161 
getScriptingContentSignatureDefaultStreamName()162 ::rtl::OUString DocumentDigitalSignatures::getScriptingContentSignatureDefaultStreamName()
163     throw (css::uno::RuntimeException)
164 {
165 	return DocumentSignatureHelper::GetScriptingContentSignatureDefaultStreamName();
166 }
167 
168 
signPackage(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XStream> & xSignStream)169 sal_Bool DocumentDigitalSignatures::signPackage(
170     const Reference< css::embed::XStorage >& rxStorage,
171     const Reference< css::io::XStream >& xSignStream  ) throw (RuntimeException)
172 {
173     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
174     return ImplViewSignatures( rxStorage, xSignStream, SignatureModePackage, false );
175 }
176 
177 Sequence< css::security::DocumentSignatureInformation >
verifyPackageSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)178 DocumentDigitalSignatures::verifyPackageSignatures(
179     const Reference< css::embed::XStorage >& rxStorage,
180     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
181 {
182     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
183     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModePackage );
184 }
185 
showPackageSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignInStream)186 void DocumentDigitalSignatures::showPackageSignatures(
187     const Reference< css::embed::XStorage >& rxStorage,
188     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException)
189 {
190     OSL_ENSURE(m_sODFVersion.getLength(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
191     ImplViewSignatures( rxStorage, xSignInStream, SignatureModePackage, true );
192 }
193 
getPackageSignatureDefaultStreamName()194 ::rtl::OUString DocumentDigitalSignatures::getPackageSignatureDefaultStreamName(  )
195     throw (::com::sun::star::uno::RuntimeException)
196 {
197 	return DocumentSignatureHelper::GetPackageSignatureDefaultStreamName();
198 }
199 
200 
ImplViewSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignStream,DocumentSignatureMode eMode,bool bReadOnly)201 sal_Bool DocumentDigitalSignatures::ImplViewSignatures(
202     const Reference< css::embed::XStorage >& rxStorage,
203     const Reference< css::io::XInputStream >& xSignStream,
204     DocumentSignatureMode eMode, bool bReadOnly ) throw (RuntimeException)
205 {
206 	Reference< io::XStream > xStream;
207 	if ( xSignStream.is() )
208 		xStream = Reference< io::XStream >( xSignStream, UNO_QUERY );
209 	return ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly );
210 }
211 
ImplViewSignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XStream> & xSignStream,DocumentSignatureMode eMode,bool bReadOnly)212 sal_Bool DocumentDigitalSignatures::ImplViewSignatures(
213     const Reference< css::embed::XStorage >& rxStorage, const Reference< css::io::XStream >& xSignStream,
214     DocumentSignatureMode eMode, bool bReadOnly ) throw (RuntimeException)
215 {
216     sal_Bool bChanges = sal_False;
217     DigitalSignaturesDialog aSignaturesDialog(
218         NULL, mxCtx, eMode, bReadOnly, m_sODFVersion, m_bHasDocumentSignature);
219     bool bInit = aSignaturesDialog.Init();
220     DBG_ASSERT( bInit, "Error initializing security context!" );
221     if ( bInit )
222     {
223         aSignaturesDialog.SetStorage( rxStorage );
224         aSignaturesDialog.SetSignatureStream( xSignStream );
225         if ( aSignaturesDialog.Execute() )
226         {
227             if ( aSignaturesDialog.SignaturesChanged() )
228     		{
229     			bChanges = sal_True;
230     			// If we have a storage and no stream, we are responsible for commit
231     			if ( rxStorage.is() && !xSignStream.is() )
232     			{
233                     uno::Reference< embed::XTransactedObject > xTrans( rxStorage, uno::UNO_QUERY );
234                     xTrans->commit();
235     			}
236     		}
237     	}
238     }
239     else
240     {
241         WarningBox aBox( NULL, XMLSEC_RES( RID_XMLSECWB_NO_MOZILLA_PROFILE ) );
242         aBox.Execute();
243     }
244 
245     return bChanges;
246 }
247 
248 Sequence< css::security::DocumentSignatureInformation >
ImplVerifySignatures(const Reference<css::embed::XStorage> & rxStorage,const Reference<css::io::XInputStream> & xSignStream,DocumentSignatureMode eMode)249 DocumentDigitalSignatures::ImplVerifySignatures(
250     const Reference< css::embed::XStorage >& rxStorage,
251     const Reference< css::io::XInputStream >& xSignStream, DocumentSignatureMode eMode ) throw (RuntimeException)
252 {
253     if (!rxStorage.is())
254     {
255         DBG_ASSERT(0, "Error, no XStorage provided");
256         return Sequence<css::security::DocumentSignatureInformation>();
257     }
258 	// First check for the InputStream, to avoid unnecessary initialization of the security environemnt...
259 	SignatureStreamHelper aStreamHelper;
260 	Reference< io::XInputStream > xInputStream = xSignStream;
261 
262 	if ( !xInputStream.is() )
263 	{
264 		aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( rxStorage, embed::ElementModes::READ, eMode );
265 		if ( aStreamHelper.xSignatureStream.is() )
266 			xInputStream = Reference< io::XInputStream >( aStreamHelper.xSignatureStream, UNO_QUERY );
267 	}
268 
269 	if ( !xInputStream.is() )
270 		return Sequence< ::com::sun::star::security::DocumentSignatureInformation >(0);
271 
272 
273 	XMLSignatureHelper aSignatureHelper( mxCtx );
274 
275     bool bInit = aSignatureHelper.Init();
276 
277 	DBG_ASSERT( bInit, "Error initializing security context!" );
278 
279 	if ( !bInit )
280 		return Sequence< ::com::sun::star::security::DocumentSignatureInformation >(0);
281 
282 	aSignatureHelper.SetStorage(rxStorage, m_sODFVersion);
283 
284     aSignatureHelper.StartMission();
285 
286 	aSignatureHelper.ReadAndVerifySignature( xInputStream );
287 
288     aSignatureHelper.EndMission();
289 
290     Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecEnv = aSignatureHelper.GetSecurityEnvironment();
291 
292     SignatureInformations aSignInfos = aSignatureHelper.GetSignatureInformations();
293 	int nInfos = aSignInfos.size();
294     Sequence< css::security::DocumentSignatureInformation > aInfos(nInfos);
295     css::security::DocumentSignatureInformation* arInfos = aInfos.getArray();
296 
297     if ( nInfos )
298     {
299        Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
300             ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
301 
302         for( int n = 0; n < nInfos; ++n )
303         {
304             DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
305                 m_sODFVersion, aSignInfos[n]);
306             const std::vector< rtl::OUString > aElementsToBeVerified =
307                 DocumentSignatureHelper::CreateElementList(
308                 rxStorage, ::rtl::OUString(), eMode, mode);
309 
310 		    const SignatureInformation& rInfo = aSignInfos[n];
311             css::security::DocumentSignatureInformation& rSigInfo = arInfos[n];
312 
313             if (rInfo.ouX509Certificate.getLength())
314            	rSigInfo.Signer = xSecEnv->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
315             if (!rSigInfo.Signer.is())
316                 rSigInfo.Signer = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) );
317 
318             // --> PB 2004-12-14 #i38744# time support again
319             Date aDate( rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year );
320             Time aTime( rInfo.stDateTime.Hours, rInfo.stDateTime.Minutes,
321                         rInfo.stDateTime.Seconds, rInfo.stDateTime.HundredthSeconds );
322             rSigInfo.SignatureDate = aDate.GetDate();
323             rSigInfo.SignatureTime = aTime.GetTime();
324 
325             // Verify certificate
326             //We have patched our version of libxmlsec, so that it does not verify the certificates. This has two
327             //reasons. First we want two separate status for signature and certificate. Second libxmlsec calls
328             //CERT_VerifyCertificate (solaris, linux) falsly, so that it always regards the certificate as valid.
329             //On Window the checking of the certificate path is buggy. It does name matching (issuer, subject name)
330             //to find the parent certificate. It does not take into account that there can be several certificates
331             //with the same subject name.
332             if (rSigInfo.Signer.is())
333             {
334                 try {
335                     rSigInfo.CertificateStatus = xSecEnv->verifyCertificate(rSigInfo.Signer,
336                         Sequence<Reference<css::security::XCertificate> >());
337                 } catch (SecurityException& ) {
338                     OSL_ENSURE(0, "Verification of certificate failed");
339                     rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
340                 }
341             }
342             else
343             {
344                 //We should always be aible to get the certificates because it is contained in the document,
345 				//unless the document is damaged so that signature xml file could not be parsed.
346                 rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
347             }
348 
349             rSigInfo.SignatureIsValid = ( rInfo.nStatus == ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED );
350 
351 
352             if ( rSigInfo.SignatureIsValid )
353             {
354                  rSigInfo.SignatureIsValid =
355                       DocumentSignatureHelper::checkIfAllFilesAreSigned(
356                       aElementsToBeVerified, rInfo, mode);
357             }
358             if (eMode == SignatureModeDocumentContent)
359                 rSigInfo.PartialDocumentSignature =
360                     ! DocumentSignatureHelper::isOOo3_2_Signature(aSignInfos[n]);
361 
362         }
363     }
364     return aInfos;
365 
366 }
367 
manageTrustedSources()368 void DocumentDigitalSignatures::manageTrustedSources(  ) throw (RuntimeException)
369 {
370 	// MT: i45295
371 	// SecEnv is only needed to display certificate information from trusted sources.
372 	// Macro Security also has some options where no security environment is needed, so raise dialog anyway.
373 	// Later I should change the code so the Dialog creates the SecEnv on demand...
374 
375 	Reference< dcss::xml::crypto::XSecurityEnvironment > xSecEnv;
376 
377 	XMLSignatureHelper aSignatureHelper( mxCtx );
378 	if ( aSignatureHelper.Init() )
379 		xSecEnv = aSignatureHelper.GetSecurityEnvironment();
380 
381 	MacroSecurity aDlg( NULL, mxCtx, xSecEnv );
382 	aDlg.Execute();
383 }
384 
showCertificate(const Reference<css::security::XCertificate> & _Certificate)385 void DocumentDigitalSignatures::showCertificate(
386     const Reference< css::security::XCertificate >& _Certificate ) throw (RuntimeException)
387 {
388     XMLSignatureHelper aSignatureHelper( mxCtx );
389 
390 	bool bInit = aSignatureHelper.Init();
391 
392 	DBG_ASSERT( bInit, "Error initializing security context!" );
393 
394 	if ( bInit )
395 	{
396 		CertificateViewer aViewer( NULL, aSignatureHelper.GetSecurityEnvironment(), _Certificate, sal_False );
397 		aViewer.Execute();
398 	}
399 
400 }
401 
isAuthorTrusted(const Reference<css::security::XCertificate> & Author)402 ::sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
403     const Reference< css::security::XCertificate >& Author ) throw (RuntimeException)
404 {
405 	sal_Bool bFound = sal_False;
406 
407     Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
408         ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
409 
410 	::rtl::OUString sSerialNum = xSerialNumberAdapter->toString( Author->getSerialNumber() );
411 
412     Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = SvtSecurityOptions().GetTrustedAuthors();
413 	const SvtSecurityOptions::Certificate* pAuthors = aTrustedAuthors.getConstArray();
414 	const SvtSecurityOptions::Certificate* pAuthorsEnd = pAuthors + aTrustedAuthors.getLength();
415 	for ( ; pAuthors != pAuthorsEnd; ++pAuthors )
416 	{
417 		SvtSecurityOptions::Certificate aAuthor = *pAuthors;
418 		if ( ( aAuthor[0] == Author->getIssuerName() ) && ( aAuthor[1] == sSerialNum ) )
419 		{
420 			bFound = sal_True;
421 			break;
422 		}
423 	}
424 
425 	return bFound;
426 }
427 
isLocationTrusted(const::rtl::OUString & Location)428 ::sal_Bool DocumentDigitalSignatures::isLocationTrusted( const ::rtl::OUString& Location ) throw (RuntimeException)
429 {
430 	sal_Bool bFound = sal_False;
431 	INetURLObject aLocObj( Location );
432 	INetURLObject aLocObjLowCase( Location.toAsciiLowerCase() ); // will be used for case insensitive comparing
433 
434 	::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider > xContentProvider;
435 	::ucbhelper::ContentBroker* pBroker = NULL;
436 
437     //warning free code
438 	//if ( aLocObj.GetProtocol() == INET_PROT_FILE && ( pBroker = ::ucbhelper::ContentBroker::get() ) )
439 	//	xContentProvider = pBroker->getContentProviderInterface();
440 	if ( aLocObj.GetProtocol() == INET_PROT_FILE)
441     {
442         pBroker = ::ucbhelper::ContentBroker::get();
443         if (pBroker)
444 		    xContentProvider = pBroker->getContentProviderInterface();
445     }
446 
447     Sequence< ::rtl::OUString > aSecURLs = SvtSecurityOptions().GetSecureURLs();
448 	const ::rtl::OUString* pSecURLs = aSecURLs.getConstArray();
449 	const ::rtl::OUString* pSecURLsEnd = pSecURLs + aSecURLs.getLength();
450 	for ( ; pSecURLs != pSecURLsEnd && !bFound; ++pSecURLs )
451 		bFound = ::utl::UCBContentHelper::IsSubPath( *pSecURLs, Location, xContentProvider );
452 
453 	return bFound;
454 }
455 
addAuthorToTrustedSources(const Reference<css::security::XCertificate> & Author)456 void DocumentDigitalSignatures::addAuthorToTrustedSources(
457     const Reference< css::security::XCertificate >& Author ) throw (RuntimeException)
458 {
459     SvtSecurityOptions aSecOpts;
460 
461     Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
462         ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
463 
464     SvtSecurityOptions::Certificate aNewCert( 3 );
465     aNewCert[ 0 ] = Author->getIssuerName();
466     aNewCert[ 1 ] = xSerialNumberAdapter->toString( Author->getSerialNumber() );
467 
468     rtl::OUStringBuffer aStrBuffer;
469     SvXMLUnitConverter::encodeBase64(aStrBuffer, Author->getEncoded());
470     aNewCert[ 2 ] = aStrBuffer.makeStringAndClear();
471 
472 
473     Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = aSecOpts.GetTrustedAuthors();
474     sal_Int32 nCnt = aTrustedAuthors.getLength();
475     aTrustedAuthors.realloc( nCnt + 1 );
476     aTrustedAuthors[ nCnt ] = aNewCert;
477 
478     aSecOpts.SetTrustedAuthors( aTrustedAuthors );
479 }
480 
addLocationToTrustedSources(const::rtl::OUString & Location)481 void DocumentDigitalSignatures::addLocationToTrustedSources( const ::rtl::OUString& Location ) throw (RuntimeException)
482 {
483     SvtSecurityOptions aSecOpt;
484 
485 	Sequence< ::rtl::OUString > aSecURLs = aSecOpt.GetSecureURLs();
486     sal_Int32 nCnt = aSecURLs.getLength();
487     aSecURLs.realloc( nCnt + 1 );
488     aSecURLs[ nCnt ] = Location;
489 
490 	aSecOpt.SetSecureURLs( aSecURLs );
491 }
492 
GetImplementationName()493 rtl::OUString DocumentDigitalSignatures::GetImplementationName() throw (RuntimeException)
494 {
495 	return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) );
496 }
497 
GetSupportedServiceNames()498 Sequence< rtl::OUString > DocumentDigitalSignatures::GetSupportedServiceNames() throw (cssu::RuntimeException)
499 {
500 	Sequence < rtl::OUString > aRet(1);
501 	rtl::OUString* pArray = aRet.getArray();
502 	pArray[0] =  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) );
503 	return aRet;
504 }
505 
506 
DocumentDigitalSignatures_CreateInstance(const Reference<XComponentContext> & rCtx)507 Reference< XInterface > DocumentDigitalSignatures_CreateInstance(
508 	const Reference< XComponentContext >& rCtx) throw ( Exception )
509 {
510 	return (cppu::OWeakObject*) new DocumentDigitalSignatures( rCtx );
511 }
512 
513