bump product version to 4.1.6.2
[LibreOffice.git] / xmlsecurity / source / helper / xsecctl.cxx
blobaddfc3ea3d2bab912f7f40fa0aee4c9d1a666b84
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <xsecctl.hxx>
22 #include <tools/debug.hxx>
24 #include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
25 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
26 #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp>
27 #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
28 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
29 #include <com/sun/star/xml/crypto/SecurityOperationStatus.hpp>
31 #include <xmloff/attrlist.hxx>
32 #include <rtl/math.hxx>
33 #include <unotools/datetime.hxx>
35 namespace cssu = com::sun::star::uno;
36 namespace cssl = com::sun::star::lang;
37 namespace cssxc = com::sun::star::xml::crypto;
38 namespace cssxs = com::sun::star::xml::sax;
39 namespace cssxw = com::sun::star::xml::wrapper;
41 const sal_Int8 XML_MAXDIGITSCOUNT_TIME = 11;
42 const sal_Int8 XML_MAXDIGITSCOUNT_DATETIME = 6;
44 /* bridge component names */
45 #define XMLSIGNATURE_COMPONENT "com.sun.star.xml.crypto.XMLSignature"
46 #define XMLDOCUMENTWRAPPER_COMPONENT "com.sun.star.xml.wrapper.XMLDocumentWrapper"
48 /* xml security framework components */
49 #define SAXEVENTKEEPER_COMPONENT "com.sun.star.xml.crypto.sax.SAXEventKeeper"
51 XSecController::XSecController( const cssu::Reference<cssu::XComponentContext>& rxCtx )
52 :mxCtx(rxCtx),
53 m_nNextSecurityId(1),
54 m_bIsSAXEventKeeperConnected(false),
55 m_nStatusOfSecurityComponents(UNINITIALIZED),
56 m_bIsSAXEventKeeperSticky(false),
57 m_pErrorMessage(NULL),
58 m_pXSecParser(NULL)
62 XSecController::~XSecController()
68 * private methods
70 int XSecController::findSignatureInfor( sal_Int32 nSecurityId) const
71 /****** XSecController/findSignatureInfor *************************************
73 * NAME
74 * findSignatureInfor -- find SignatureInformation struct for a particular
75 * signature
77 * SYNOPSIS
78 * index = findSignatureInfor( nSecurityId );
80 * FUNCTION
81 * see NAME.
83 * INPUTS
84 * nSecurityId - the signature's id
86 * RESULT
87 * index - the index of the signature, or -1 when no such signature
88 * existing
90 * AUTHOR
91 * Michael Mi
92 * Email: michael.mi@sun.com
93 ******************************************************************************/
95 int i;
96 int size = m_vInternalSignatureInformations.size();
98 for (i=0; i<size; ++i)
100 if (m_vInternalSignatureInformations[i].signatureInfor.nSecurityId == nSecurityId)
102 return i;
106 return -1;
109 void XSecController::createXSecComponent( )
110 /****** XSecController/createXSecComponent ************************************
112 * NAME
113 * bResult = createXSecComponent -- creates xml security components
115 * SYNOPSIS
116 * createXSecComponent( );
118 * FUNCTION
119 * Creates xml security components, including:
120 * 1. an xml signature bridge component ( Java based or C based)
121 * 2. an XMLDocumentWrapper component ( Java based or C based)
122 * 3. a SAXEventKeeper component
124 * INPUTS
125 * empty
127 * RESULT
128 * empty
130 * AUTHOR
131 * Michael Mi
132 * Email: michael.mi@sun.com
133 ******************************************************************************/
135 OUString sSAXEventKeeper( SAXEVENTKEEPER_COMPONENT );
136 OUString sXMLSignature( XMLSIGNATURE_COMPONENT );
137 OUString sXMLDocument( XMLDOCUMENTWRAPPER_COMPONENT );
140 * marks all security components are not available.
142 m_nStatusOfSecurityComponents = FAILTOINITIALIZED;
143 m_xXMLSignature = NULL;
144 m_xXMLDocumentWrapper = NULL;
145 m_xSAXEventKeeper = NULL;
147 cssu::Reference< cssl::XMultiComponentFactory > xMCF( mxCtx->getServiceManager() );
149 m_xXMLSignature = cssu::Reference< cssxc::XXMLSignature >(
150 xMCF->createInstanceWithContext( sXMLSignature, mxCtx ),
151 cssu::UNO_QUERY );
153 bool bSuccess = (0!=m_xXMLSignature.is());
154 if ( bSuccess )
156 * XMLSignature created successfully.
159 m_xXMLDocumentWrapper = cssu::Reference< cssxw::XXMLDocumentWrapper >(
160 xMCF->createInstanceWithContext( sXMLDocument, mxCtx ),
161 cssu::UNO_QUERY );
164 bSuccess &= (0!=m_xXMLDocumentWrapper.is());
165 if ( bSuccess )
167 * XMLDocumentWrapper created successfully.
170 m_xSAXEventKeeper = cssu::Reference< cssxc::sax::XSecuritySAXEventKeeper >(
171 xMCF->createInstanceWithContext( sSAXEventKeeper, mxCtx ),
172 cssu::UNO_QUERY );
175 bSuccess &= (0!=m_xSAXEventKeeper.is());
177 if (bSuccess)
179 * SAXEventKeeper created successfully.
182 cssu::Reference< cssl::XInitialization > xInitialization(m_xSAXEventKeeper, cssu::UNO_QUERY);
184 cssu::Sequence <cssu::Any> arg(1);
185 arg[0] = cssu::makeAny(m_xXMLDocumentWrapper);
186 xInitialization->initialize(arg);
188 cssu::Reference<cssxc::sax::XSAXEventKeeperStatusChangeBroadcaster>
189 xSAXEventKeeperStatusChangeBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY);
190 cssu::Reference< cssxc::sax::XSAXEventKeeperStatusChangeListener >
191 xStatusChangeListener = this;
193 xSAXEventKeeperStatusChangeBroadcaster
194 ->addSAXEventKeeperStatusChangeListener( xStatusChangeListener );
196 m_nStatusOfSecurityComponents = INITIALIZED;
200 bool XSecController::chainOn( bool bRetrievingLastEvent )
201 /****** XSecController/chainOn ************************************************
203 * NAME
204 * chainOn -- tyies to connect the SAXEventKeeper with the SAX chain.
206 * SYNOPSIS
207 * bJustChainingOn = chainOn( bRetrievingLastEvent );
209 * FUNCTION
210 * First, checks whether the SAXEventKeeper is on the SAX chain. If not,
211 * creates xml security components, and chains the SAXEventKeeper into
212 * the SAX chain.
213 * Before being chained in, the SAXEventKeeper needs to receive all
214 * missed key SAX events, which can promise the DOM tree bufferred by the
215 * SAXEventKeeper has the same structure with the original document.
217 * INPUTS
218 * bRetrievingLastEvent - whether to retrieve the last key SAX event from
219 * the ElementStackKeeper.
221 * RESULT
222 * bJustChainingOn - whether the SAXEventKeeper is just chained into the
223 * SAX chain.
225 * NOTES
226 * Sometimes, the last key SAX event can't be transferred to the
227 * SAXEventKeeper together.
228 * For instance, at the time an referenced element is detected, the
229 * startElement event has already been reserved by the ElementStackKeeper.
230 * Meanwhile, an ElementCollector needs to be created before the
231 * SAXEventKeeper receives that startElement event.
232 * So for the SAXEventKeeper, it needs to receive all missed key SAX
233 * events except that startElement event, then adds a new
234 * ElementCollector, then receives that startElement event.
236 * AUTHOR
237 * Michael Mi
238 * Email: michael.mi@sun.com
239 ******************************************************************************/
241 bool rc = false;
243 if (!m_bIsSAXEventKeeperSticky && !m_bIsSAXEventKeeperConnected)
245 if ( m_nStatusOfSecurityComponents == UNINITIALIZED )
247 createXSecComponent();
250 if ( m_nStatusOfSecurityComponents == INITIALIZED )
252 * if all security components are ready, chains on the SAXEventKeeper
256 * disconnect the SAXEventKeeper with its current output handler,
257 * to make sure no SAX event is forwarded during the connecting
258 * phase.
260 m_xSAXEventKeeper->setNextHandler( NULL );
262 cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(m_xSAXEventKeeper, cssu::UNO_QUERY);
265 * connects the previous document handler on the SAX chain
267 if ( m_xPreviousNodeOnSAXChain.is() )
269 if ( m_bIsPreviousNodeInitializable )
271 cssu::Reference< cssl::XInitialization > xInitialization
272 (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
274 cssu::Sequence<cssu::Any> aArgs( 1 );
275 aArgs[0] <<= xSEKHandler;
276 xInitialization->initialize(aArgs);
278 else
280 cssu::Reference< cssxs::XParser > xParser
281 (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
282 xParser->setDocumentHandler( xSEKHandler );
287 * get missed key SAX events
289 if (m_xElementStackKeeper.is())
291 m_xElementStackKeeper->retrieve(xSEKHandler, bRetrievingLastEvent);
294 * now the ElementStackKeeper can stop its work, because the
295 * SAXEventKeeper is on the SAX chain, no SAX events will be
296 * missed.
298 m_xElementStackKeeper->stop();
302 * connects the next document handler on the SAX chain
304 m_xSAXEventKeeper->setNextHandler( m_xNextNodeOnSAXChain );
306 m_bIsSAXEventKeeperConnected = true;
308 rc = true;
312 return rc;
315 void XSecController::chainOff()
316 /****** XSecController/chainOff ***********************************************
318 * NAME
319 * chainOff -- disconnects the SAXEventKeeper from the SAX chain.
321 * SYNOPSIS
322 * chainOff( );
324 * FUNCTION
325 * See NAME.
327 * INPUTS
328 * empty
330 * RESULT
331 * empty
333 * AUTHOR
334 * Michael Mi
335 * Email: michael.mi@sun.com
336 ******************************************************************************/
338 if (!m_bIsSAXEventKeeperSticky )
340 if (m_bIsSAXEventKeeperConnected)
342 m_xSAXEventKeeper->setNextHandler( NULL );
344 if ( m_xPreviousNodeOnSAXChain.is() )
346 if ( m_bIsPreviousNodeInitializable )
348 cssu::Reference< cssl::XInitialization > xInitialization
349 (m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
351 cssu::Sequence<cssu::Any> aArgs( 1 );
352 aArgs[0] <<= m_xNextNodeOnSAXChain;
353 xInitialization->initialize(aArgs);
355 else
357 cssu::Reference< cssxs::XParser > xParser(m_xPreviousNodeOnSAXChain, cssu::UNO_QUERY);
358 xParser->setDocumentHandler( m_xNextNodeOnSAXChain );
362 if (m_xElementStackKeeper.is())
365 * start the ElementStackKeeper to reserve any possible
366 * missed key SAX events
368 m_xElementStackKeeper->start();
371 m_bIsSAXEventKeeperConnected = false;
376 void XSecController::checkChainingStatus()
377 /****** XSecController/checkChainingStatus ************************************
379 * NAME
380 * checkChainingStatus -- connects or disconnects the SAXEventKeeper
381 * according to the current situation.
383 * SYNOPSIS
384 * checkChainingStatus( );
386 * FUNCTION
387 * The SAXEventKeeper is chained into the SAX chain, when:
388 * 1. some element is being collected, or
389 * 2. the SAX event stream is blocking.
390 * Otherwise, chain off the SAXEventKeeper.
392 * INPUTS
393 * empty
395 * RESULT
396 * empty
398 * AUTHOR
399 * Michael Mi
400 * Email: michael.mi@sun.com
401 ******************************************************************************/
403 if ( m_bIsCollectingElement || m_bIsBlocking )
405 chainOn(true);
407 else
409 chainOff();
413 void XSecController::initializeSAXChain()
414 /****** XSecController/initializeSAXChain *************************************
416 * NAME
417 * initializeSAXChain -- initializes the SAX chain according to the
418 * current setting.
420 * SYNOPSIS
421 * initializeSAXChain( );
423 * FUNCTION
424 * Initializes the SAX chain, if the SAXEventKeeper is asked to be always
425 * on the SAX chain, chains it on. Otherwise, starts the
426 * ElementStackKeeper to reserve key SAX events.
428 * INPUTS
429 * empty
431 * RESULT
432 * empty
434 * AUTHOR
435 * Michael Mi
436 * Email: michael.mi@sun.com
437 ******************************************************************************/
439 m_bIsSAXEventKeeperConnected = false;
440 m_bIsCollectingElement = false;
441 m_bIsBlocking = false;
443 if (m_xElementStackKeeper.is())
446 * starts the ElementStackKeeper
448 m_xElementStackKeeper->start();
451 chainOff();
454 cssu::Reference< com::sun::star::io::XInputStream >
455 XSecController::getObjectInputStream( const OUString& objectURL )
456 /****** XSecController/getObjectInputStream ************************************
458 * NAME
459 * getObjectInputStream -- get a XInputStream interface from a SvStorage
461 * SYNOPSIS
462 * xInputStream = getObjectInputStream( objectURL );
464 * FUNCTION
465 * See NAME.
467 * INPUTS
468 * objectURL - the object uri
470 * RESULT
471 * xInputStream - the XInputStream interface
473 * AUTHOR
474 * Michael Mi
475 * Email: michael.mi@sun.com
476 ******************************************************************************/
478 cssu::Reference< com::sun::star::io::XInputStream > xObjectInputStream;
480 DBG_ASSERT( m_xUriBinding.is(), "Need XUriBinding!" );
482 xObjectInputStream = m_xUriBinding->getUriBinding(objectURL);
484 return xObjectInputStream;
488 * public methods
491 sal_Int32 XSecController::getNewSecurityId( )
493 sal_Int32 nId = m_nNextSecurityId;
494 m_nNextSecurityId++;
495 return nId;
498 void XSecController::startMission(
499 const cssu::Reference< cssxc::XUriBinding >& xUriBinding,
500 const cssu::Reference< cssxc::XXMLSecurityContext >& xSecurityContext )
501 /****** XSecController/startMission *******************************************
503 * NAME
504 * startMission -- starts a new security mission.
506 * SYNOPSIS
507 * startMission( xUriBinding, xSecurityContect );
509 * FUNCTION
510 * get ready for a new mission.
512 * INPUTS
513 * xUriBinding - the Uri binding that provide maps between uris and
514 * XInputStreams
515 * xSecurityContext - the security context component which can provide
516 * cryptoken
518 * RESULT
519 * empty
521 * AUTHOR
522 * Michael Mi
523 * Email: michael.mi@sun.com
524 ******************************************************************************/
526 m_xUriBinding = xUriBinding;
528 m_nStatusOfSecurityComponents = UNINITIALIZED;
529 m_xSecurityContext = xSecurityContext;
530 m_pErrorMessage = NULL;
532 m_vInternalSignatureInformations.clear();
534 m_bVerifyCurrentSignature = false;
537 void XSecController::setSAXChainConnector(
538 const cssu::Reference< cssl::XInitialization >& xInitialization,
539 const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler,
540 const cssu::Reference< cssxc::sax::XElementStackKeeper >& xElementStackKeeper)
541 /****** XSecController/setSAXChainConnector ***********************************
543 * NAME
544 * setSAXChainConnector -- configures the components which will
545 * collaborate with the SAXEventKeeper on the SAX chain.
547 * SYNOPSIS
548 * setSAXChainConnector( xInitialization,
549 * xDocumentHandler,
550 * xElementStackKeeper );
552 * FUNCTION
553 * See NAME.
555 * INPUTS
556 * xInitialization - the previous node on the SAX chain
557 * xDocumentHandler - the next node on the SAX chain
558 * xElementStackKeeper - the ElementStackKeeper component which reserves
559 * missed key SAX events for the SAXEventKeeper
561 * RESULT
562 * empty
564 * AUTHOR
565 * Michael Mi
566 * Email: michael.mi@sun.com
567 ******************************************************************************/
569 m_bIsPreviousNodeInitializable = true;
570 m_xPreviousNodeOnSAXChain = xInitialization;
571 m_xNextNodeOnSAXChain = xDocumentHandler;
572 m_xElementStackKeeper = xElementStackKeeper;
574 initializeSAXChain( );
577 void XSecController::clearSAXChainConnector()
578 /****** XSecController/clearSAXChainConnector *********************************
580 * NAME
581 * clearSAXChainConnector -- resets the collaborating components.
583 * SYNOPSIS
584 * clearSAXChainConnector( );
586 * FUNCTION
587 * See NAME.
589 * INPUTS
590 * empty
592 * RESULT
593 * empty
595 * AUTHOR
596 * Michael Mi
597 * Email: michael.mi@sun.com
598 ******************************************************************************/
601 * before reseting, if the ElementStackKeeper has kept something, then
602 * those kept key SAX events must be transferred to the SAXEventKeeper
603 * first. This is to promise the next node to the SAXEventKeeper on the
604 * SAX chain always receives a complete document.
606 if (m_xElementStackKeeper.is() && m_xSAXEventKeeper.is())
608 cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(m_xSAXEventKeeper, cssu::UNO_QUERY);
609 m_xElementStackKeeper->retrieve(xSEKHandler, sal_True);
612 chainOff();
614 m_xPreviousNodeOnSAXChain = NULL;
615 m_xNextNodeOnSAXChain = NULL;
616 m_xElementStackKeeper = NULL;
619 void XSecController::endMission()
620 /****** XSecController/endMission *********************************************
622 * NAME
623 * endMission -- forces to end all missions
625 * SYNOPSIS
626 * endMission( );
628 * FUNCTION
629 * Deletes all signature information and forces all missions to an end.
631 * INPUTS
632 * empty
634 * RESULT
635 * empty
637 * AUTHOR
638 * Michael Mi
639 * Email: michael.mi@sun.com
640 ******************************************************************************/
642 sal_Int32 size = m_vInternalSignatureInformations.size();
644 for (int i=0; i<size; ++i)
646 if ( m_nStatusOfSecurityComponents == INITIALIZED )
648 * ResolvedListener only exist when the security components are created.
651 cssu::Reference< cssxc::sax::XMissionTaker > xMissionTaker
652 ( m_vInternalSignatureInformations[i].xReferenceResolvedListener, cssu::UNO_QUERY );
655 * askes the SignatureCreator/SignatureVerifier to release
656 * all resouces it uses.
658 xMissionTaker->endMission();
662 m_xUriBinding = NULL;
663 m_xSecurityContext = NULL;
666 * free the status change listener reference to this object
668 if (m_xSAXEventKeeper.is())
670 cssu::Reference<cssxc::sax::XSAXEventKeeperStatusChangeBroadcaster>
671 xSAXEventKeeperStatusChangeBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY);
672 xSAXEventKeeperStatusChangeBroadcaster
673 ->addSAXEventKeeperStatusChangeListener( NULL );
677 void XSecController::exportSignature(
678 const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler,
679 const SignatureInformation& signatureInfo )
680 /****** XSecController/exportSignature ****************************************
682 * NAME
683 * exportSignature -- export a signature structure to an XDocumentHandler
685 * SYNOPSIS
686 * exportSignature( xDocumentHandler, signatureInfo);
688 * FUNCTION
689 * see NAME.
691 * INPUTS
692 * xDocumentHandler - the document handler to receive the signature
693 * signatureInfo - signature to be exported
695 * RESULT
696 * empty
698 * AUTHOR
699 * Michael Mi
700 * Email: michael.mi@sun.com
701 ******************************************************************************/
704 * defines all element tags in Signature element.
706 OUString tag_Signature(TAG_SIGNATURE);
707 OUString tag_SignedInfo(TAG_SIGNEDINFO);
708 OUString tag_CanonicalizationMethod(TAG_CANONICALIZATIONMETHOD);
709 OUString tag_SignatureMethod(TAG_SIGNATUREMETHOD);
710 OUString tag_Reference(TAG_REFERENCE);
711 OUString tag_Transforms(TAG_TRANSFORMS);
712 OUString tag_Transform(TAG_TRANSFORM);
713 OUString tag_DigestMethod(TAG_DIGESTMETHOD);
714 OUString tag_DigestValue(TAG_DIGESTVALUE);
715 OUString tag_SignatureValue(TAG_SIGNATUREVALUE);
716 OUString tag_KeyInfo(TAG_KEYINFO);
717 OUString tag_X509Data(TAG_X509DATA);
718 OUString tag_X509IssuerSerial(TAG_X509ISSUERSERIAL);
719 OUString tag_X509IssuerName(TAG_X509ISSUERNAME);
720 OUString tag_X509SerialNumber(TAG_X509SERIALNUMBER);
721 OUString tag_X509Certificate(TAG_X509CERTIFICATE);
722 OUString tag_Object(TAG_OBJECT);
723 OUString tag_SignatureProperties(TAG_SIGNATUREPROPERTIES);
724 OUString tag_SignatureProperty(TAG_SIGNATUREPROPERTY);
725 OUString tag_Date(TAG_DATE);
727 const SignatureReferenceInformations& vReferenceInfors = signatureInfo.vSignatureReferenceInfors;
728 SvXMLAttributeList *pAttributeList;
731 * Write Signature element
733 pAttributeList = new SvXMLAttributeList();
734 pAttributeList->AddAttribute(
735 OUString(ATTR_XMLNS),
736 OUString(NS_XMLDSIG));
738 if (!signatureInfo.ouSignatureId.isEmpty())
740 pAttributeList->AddAttribute(
741 OUString(ATTR_ID),
742 OUString(signatureInfo.ouSignatureId));
745 xDocumentHandler->startElement( tag_Signature, cssu::Reference< cssxs::XAttributeList > (pAttributeList));
747 /* Write SignedInfo element */
748 xDocumentHandler->startElement(
749 tag_SignedInfo,
750 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
752 /* Write CanonicalizationMethod element */
753 pAttributeList = new SvXMLAttributeList();
754 pAttributeList->AddAttribute(
755 OUString(ATTR_ALGORITHM),
756 OUString(ALGO_C14N));
757 xDocumentHandler->startElement( tag_CanonicalizationMethod, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
758 xDocumentHandler->endElement( tag_CanonicalizationMethod );
760 /* Write SignatureMethod element */
761 pAttributeList = new SvXMLAttributeList();
762 pAttributeList->AddAttribute(
763 OUString(ATTR_ALGORITHM),
764 OUString(ALGO_RSASHA1));
765 xDocumentHandler->startElement( tag_SignatureMethod, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
766 xDocumentHandler->endElement( tag_SignatureMethod );
768 /* Write Reference element */
769 int j;
770 int refNum = vReferenceInfors.size();
772 for(j=0; j<refNum; ++j)
774 const SignatureReferenceInformation& refInfor = vReferenceInfors[j];
776 pAttributeList = new SvXMLAttributeList();
777 if ( refInfor.nType != TYPE_SAMEDOCUMENT_REFERENCE )
779 * stream reference
782 pAttributeList->AddAttribute(
783 OUString(ATTR_URI),
784 refInfor.ouURI);
786 else
788 * same-document reference
791 pAttributeList->AddAttribute(
792 OUString(ATTR_URI),
793 OUString(CHAR_FRAGMENT)+refInfor.ouURI);
796 xDocumentHandler->startElement( tag_Reference, cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
798 /* Write Transforms element */
799 if (refInfor.nType == TYPE_XMLSTREAM_REFERENCE)
801 * xml stream, so c14n transform is needed
804 xDocumentHandler->startElement(
805 tag_Transforms,
806 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
808 pAttributeList = new SvXMLAttributeList();
809 pAttributeList->AddAttribute(
810 OUString(ATTR_ALGORITHM),
811 OUString(ALGO_C14N));
812 xDocumentHandler->startElement(
813 tag_Transform,
814 cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
815 xDocumentHandler->endElement( tag_Transform );
817 xDocumentHandler->endElement( tag_Transforms );
820 /* Write DigestMethod element */
821 pAttributeList = new SvXMLAttributeList();
822 pAttributeList->AddAttribute(
823 OUString(ATTR_ALGORITHM),
824 OUString(ALGO_XMLDSIGSHA1));
825 xDocumentHandler->startElement(
826 tag_DigestMethod,
827 cssu::Reference< cssxs::XAttributeList > (pAttributeList) );
828 xDocumentHandler->endElement( tag_DigestMethod );
830 /* Write DigestValue element */
831 xDocumentHandler->startElement(
832 tag_DigestValue,
833 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
834 xDocumentHandler->characters( refInfor.ouDigestValue );
835 xDocumentHandler->endElement( tag_DigestValue );
837 xDocumentHandler->endElement( tag_Reference );
840 xDocumentHandler->endElement( tag_SignedInfo );
842 /* Write SignatureValue element */
843 xDocumentHandler->startElement(
844 tag_SignatureValue,
845 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
846 xDocumentHandler->characters( signatureInfo.ouSignatureValue );
847 xDocumentHandler->endElement( tag_SignatureValue );
849 /* Write KeyInfo element */
850 xDocumentHandler->startElement(
851 tag_KeyInfo,
852 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
854 /* Write X509Data element */
855 xDocumentHandler->startElement(
856 tag_X509Data,
857 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
859 /* Write X509IssuerSerial element */
860 xDocumentHandler->startElement(
861 tag_X509IssuerSerial,
862 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
864 /* Write X509IssuerName element */
865 xDocumentHandler->startElement(
866 tag_X509IssuerName,
867 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
868 xDocumentHandler->characters( signatureInfo.ouX509IssuerName );
869 xDocumentHandler->endElement( tag_X509IssuerName );
871 /* Write X509SerialNumber element */
872 xDocumentHandler->startElement(
873 tag_X509SerialNumber,
874 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
875 xDocumentHandler->characters( signatureInfo.ouX509SerialNumber );
876 xDocumentHandler->endElement( tag_X509SerialNumber );
878 xDocumentHandler->endElement( tag_X509IssuerSerial );
880 /* Write X509Certificate element */
881 if (!signatureInfo.ouX509Certificate.isEmpty())
883 xDocumentHandler->startElement(
884 tag_X509Certificate,
885 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
886 xDocumentHandler->characters( signatureInfo.ouX509Certificate );
887 xDocumentHandler->endElement( tag_X509Certificate );
890 xDocumentHandler->endElement( tag_X509Data );
892 xDocumentHandler->endElement( tag_KeyInfo );
894 /* Write Object element */
895 xDocumentHandler->startElement(
896 tag_Object,
897 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
899 /* Write SignatureProperties element */
900 xDocumentHandler->startElement(
901 tag_SignatureProperties,
902 cssu::Reference< cssxs::XAttributeList > (new SvXMLAttributeList()));
904 /* Write SignatureProperty element */
905 pAttributeList = new SvXMLAttributeList();
906 pAttributeList->AddAttribute(
907 OUString(ATTR_ID),
908 signatureInfo.ouPropertyId);
909 pAttributeList->AddAttribute(
910 OUString(ATTR_TARGET),
911 OUString(CHAR_FRAGMENT)+signatureInfo.ouSignatureId);
912 xDocumentHandler->startElement(
913 tag_SignatureProperty,
914 cssu::Reference< cssxs::XAttributeList > (pAttributeList));
916 /* Write timestamp element */
918 pAttributeList = new SvXMLAttributeList();
919 pAttributeList->AddAttribute(
920 OUString(ATTR_XMLNS)
921 +OUString(":")
922 +OUString(NSTAG_DC),
923 OUString(NS_DC));
925 xDocumentHandler->startElement(
926 OUString(NSTAG_DC)
927 +OUString(":")
928 +tag_Date,
929 cssu::Reference< cssxs::XAttributeList > (pAttributeList));
931 OUStringBuffer buffer;
932 //If the xml signature was already contained in the document,
933 //then we use the original date and time string, rather then the
934 //converted one. This avoids writing a different string due to
935 //e.g. rounding issues and thus breaking the signature.
936 if (!signatureInfo.ouDateTime.isEmpty())
937 buffer = signatureInfo.ouDateTime;
938 else
940 buffer = utl::toISO8601(signatureInfo.stDateTime);
942 xDocumentHandler->characters( buffer.makeStringAndClear() );
944 xDocumentHandler->endElement(
945 OUString(NSTAG_DC)
946 +OUString(":")
947 +tag_Date);
949 xDocumentHandler->endElement( tag_SignatureProperty );
951 xDocumentHandler->endElement( tag_SignatureProperties );
953 xDocumentHandler->endElement( tag_Object );
955 xDocumentHandler->endElement( tag_Signature );
958 SignatureInformation XSecController::getSignatureInformation( sal_Int32 nSecurityId ) const
960 SignatureInformation aInf( 0 );
961 int nIndex = findSignatureInfor(nSecurityId);
962 DBG_ASSERT( nIndex != -1, "getSignatureInformation - SecurityId is invalid!" );
963 if ( nIndex != -1)
965 aInf = m_vInternalSignatureInformations[nIndex].signatureInfor;
967 return aInf;
970 SignatureInformations XSecController::getSignatureInformations() const
972 SignatureInformations vInfors;
973 int sigNum = m_vInternalSignatureInformations.size();
975 for (int i=0; i<sigNum; ++i)
977 SignatureInformation si = m_vInternalSignatureInformations[i].signatureInfor;
978 vInfors.push_back(si);
981 return vInfors;
985 * XSecurityController
987 * no methods
991 * XFastPropertySet
995 * XSAXEventKeeperStatusChangeListener
998 void SAL_CALL XSecController::blockingStatusChanged( sal_Bool isBlocking )
999 throw (cssu::RuntimeException)
1001 this->m_bIsBlocking = isBlocking;
1002 checkChainingStatus();
1005 void SAL_CALL XSecController::collectionStatusChanged(
1006 sal_Bool isInsideCollectedElement )
1007 throw (cssu::RuntimeException)
1009 this->m_bIsCollectingElement = isInsideCollectedElement;
1010 checkChainingStatus();
1013 void SAL_CALL XSecController::bufferStatusChanged( sal_Bool /*isBufferEmpty*/)
1014 throw (cssu::RuntimeException)
1020 * XSignatureCreationResultListener
1022 void SAL_CALL XSecController::signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult )
1023 throw (com::sun::star::uno::RuntimeException)
1025 int index = findSignatureInfor(securityId);
1026 DBG_ASSERT( index != -1, "Signature Not Found!" );
1028 SignatureInformation& signatureInfor = m_vInternalSignatureInformations[index].signatureInfor;
1030 signatureInfor.nStatus = nResult;
1034 * XSignatureVerifyResultListener
1036 void SAL_CALL XSecController::signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult )
1037 throw (com::sun::star::uno::RuntimeException)
1039 int index = findSignatureInfor(securityId);
1040 DBG_ASSERT( index != -1, "Signature Not Found!" );
1042 SignatureInformation& signatureInfor = m_vInternalSignatureInformations[index].signatureInfor;
1044 signatureInfor.nStatus = nResult;
1047 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */