1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package com
.sun
.star
.xml
.security
.uno
;
30 import java
.util
.Stack
;
31 import java
.util
.Vector
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.lang
.XMultiComponentFactory
;
36 import com
.sun
.star
.lang
.XInitialization
;
37 import com
.sun
.star
.uno
.XComponentContext
;
38 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
39 import com
.sun
.star
.xml
.sax
.XAttributeList
;
40 import com
.sun
.star
.xml
.sax
.SAXException
;
42 import com
.sun
.star
.xml
.crypto
.*;
43 import com
.sun
.star
.xml
.crypto
.sax
.*;
44 import com
.sun
.star
.xml
.wrapper
.*;
47 * the XMLSecurityFrameworkController class is used to controll the xml security framework.
49 public class XMLSecurityFrameworkController
50 implements XDocumentHandler
, XSignatureCreationResultListener
, XSignatureVerifyResultListener
,
51 XEncryptionResultListener
, XDecryptionResultListener
, XSAXEventKeeperStatusChangeListener
54 * UNO framework component
56 private XMultiComponentFactory m_xRemoteServiceManager
;
57 private XComponentContext m_xRemoteContext
;
60 * xml security related UNO components
62 private XSecuritySAXEventKeeper m_xSAXEventKeeper
;
63 private XXMLDocumentWrapper m_xXMLDocumentWrapper
;
64 private XDocumentHandler m_xOutputHandler
;
65 private XXMLSecurityContext m_xXMLSecurityContext
;
66 private XXMLSignature m_xXMLSignature
;
67 private XXMLEncryption m_xXMLEncryption
;
70 * used to reserve the current SAX ancestor path
72 private Stack m_currentPath
;
75 * maintains all SignatureEntities.
77 private Vector m_signatureList
;
80 * maintains all EncryptionEntities.
82 private Vector m_encryptionList
;
85 * maintains all unsolved reference Ids.
86 * These ids are strings which is the value of the id attribute
87 * of the referenced element.
89 private Vector m_vUnsolvedReferenceIds
;
92 * maintains all unsolved reference keeper ids.
93 * The keeper id is used to uniquely identify a bufferred element
94 * by the SAXEventKeeper.
96 private Vector m_vUnsolvedReferencedKeeperIds
;
99 * maintains the left time that each unsolved reference can be
102 private Vector m_vUnsolvedReferenceRefNum
;
105 * whether exporting or importing
107 private boolean m_bIsExporting
;
112 private boolean m_bIsJavaBased
;
115 * whether the SAXEventKeeper is blocking
117 private boolean m_bIsBlocking
;
120 * whether it is collecting a bufferred element
122 private boolean m_bIsInsideCollectedElement
;
125 * whether a SAXEventKeeper is in the SAX chain
127 private boolean m_bSAXEventKeeperIncluded
;
130 * the ParsingThread used to parse the document
132 private ParsingThread m_parsingThread
;
135 * the next document handler that will receives SAX events
136 * from the parsing thread.
137 * if the SAXEventKeeper is on the SAX chain, then this
138 * variable will be the SAXEventKeeper, otherwise, this
139 * variable will be the xOutputHandler.
141 private XDocumentHandler m_xExportHandler
;
144 * the TestTool used to feedback information
146 private TestTool m_testTool
;
149 * for encryption target
151 private boolean m_bIsEncryptionTarget
;
152 private EncryptionEntity m_EncryptionForTarget
;
154 XMLSecurityFrameworkController(
156 boolean bIsExporting
,
157 boolean bIsJavaBased
,
158 XDocumentHandler xOutputHandler
,
159 ParsingThread parsingThread
,
160 XXMLSecurityContext xXMLSecurityContext
,
161 XXMLSignature xXMLSignature
,
162 XXMLEncryption xXMLEncryption
,
163 XMultiComponentFactory xRemoteServiceManager
,
164 XComponentContext xRemoteContext
)
166 m_bIsExporting
= bIsExporting
;
167 m_bIsJavaBased
= bIsJavaBased
;
169 m_xOutputHandler
= xOutputHandler
;
170 m_xXMLSecurityContext
= xXMLSecurityContext
;
171 m_xXMLSignature
= xXMLSignature
;
172 m_xXMLEncryption
= xXMLEncryption
;
173 m_xRemoteServiceManager
= xRemoteServiceManager
;
174 m_xRemoteContext
= xRemoteContext
;
176 m_testTool
= testTool
;
177 m_parsingThread
= parsingThread
;
179 m_signatureList
= new Vector();
180 m_encryptionList
= new Vector();
182 m_vUnsolvedReferenceIds
= new Vector();
183 m_vUnsolvedReferencedKeeperIds
= new Vector();
184 m_vUnsolvedReferenceRefNum
= new Vector();
186 m_xXMLDocumentWrapper
= null;
187 m_xSAXEventKeeper
= null;
189 m_bSAXEventKeeperIncluded
= false;
190 m_bIsBlocking
= false;
191 m_bIsInsideCollectedElement
= false;
193 m_bIsEncryptionTarget
= false;
194 m_EncryptionForTarget
= null;
198 m_currentPath
= new Stack();
200 foundSecurityRelated();
203 /**************************************************************************************
205 **************************************************************************************/
208 * changes the output document handler.
210 private void changeOutput()
214 m_parsingThread
.setHandler(this);
217 * If the SAXEventKeeper is in the SAX chain, then redirects output
218 * to the SAXEventKeeper, otherwise, to the m_xOutputHandler
220 if (m_bSAXEventKeeperIncluded
)
222 m_xExportHandler
= (XDocumentHandler
)UnoRuntime
.queryInterface(
223 XDocumentHandler
.class, m_xSAXEventKeeper
);
224 m_xSAXEventKeeper
.setNextHandler(m_xOutputHandler
);
226 m_testTool
.updatesSAXChainInformation("XMLExporter -> SAXEventKeeper -> SAXWriter");
230 m_xExportHandler
= m_xOutputHandler
;
231 m_testTool
.updatesSAXChainInformation("XMLExporter -> SAXWriter");
236 if (m_bSAXEventKeeperIncluded
)
238 m_parsingThread
.setHandler(
239 (XDocumentHandler
)UnoRuntime
.queryInterface(XDocumentHandler
.class, m_xSAXEventKeeper
));
240 m_xSAXEventKeeper
.setNextHandler(this);
241 m_testTool
.updatesSAXChainInformation("SAXParser -> SAXEventKeeper -> XMLImporter");
245 m_parsingThread
.setHandler(this);
246 m_testTool
.updatesSAXChainInformation("SAXParser -> XMLImporter");
248 m_xExportHandler
= m_xOutputHandler
;
253 * handles the situation when a security related element is found.
254 * if the SAXEventKeeper is not initialized, then creates a
256 * the return value represents whether the SAXEventKeeper is newly
259 private boolean foundSecurityRelated()
261 if (m_xSAXEventKeeper
== null)
263 m_testTool
.showMessage("Message from : "+
264 (m_bIsExporting?
"XMLExporter":"XMLImporter")+
265 "\n\nA security related content found, a SAXEventKeeper is created.\n ");
267 m_bIsBlocking
= false;
268 m_bIsInsideCollectedElement
= false;
273 * creates an XMLDocumentWrapper component.
275 Object xmlDocumentObj
= null;
279 xmlDocumentObj
= m_xRemoteServiceManager
.createInstanceWithContext(
280 TestTool
.XMLDOCUMENTWRAPPER_COMPONENT_JAVA
, m_xRemoteContext
);
284 xmlDocumentObj
= m_xRemoteServiceManager
.createInstanceWithContext(
285 TestTool
.XMLDOCUMENTWRAPPER_COMPONENT_C
, m_xRemoteContext
);
288 m_xXMLDocumentWrapper
= (XXMLDocumentWrapper
)UnoRuntime
.queryInterface(
289 XXMLDocumentWrapper
.class, xmlDocumentObj
);
292 * creates a SAXEventKeeper component.
294 Object saxEventKeeperObj
= m_xRemoteServiceManager
.createInstanceWithContext(
295 TestTool
.SAXEVENTKEEPER_COMPONENT
, m_xRemoteContext
);
298 (XSecuritySAXEventKeeper
)UnoRuntime
.queryInterface(
299 XSecuritySAXEventKeeper
.class, saxEventKeeperObj
);
302 * initializes the SAXEventKeeper component with the XMLDocumentWrapper component.
304 XInitialization xInitialization
=
305 (XInitialization
)UnoRuntime
.queryInterface(
306 XInitialization
.class, m_xSAXEventKeeper
);
307 Object args
[]=new Object
[1];
308 args
[0] = m_xXMLDocumentWrapper
;
309 xInitialization
.initialize(args
);
311 catch( com
.sun
.star
.uno
.Exception e
)
317 * configures the SAXEventKeeper's status change listener.
319 XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster
=
320 (XSAXEventKeeperStatusChangeBroadcaster
)UnoRuntime
.queryInterface(
321 XSAXEventKeeperStatusChangeBroadcaster
.class, m_xSAXEventKeeper
);
322 xSaxEventKeeperStatusChangeBroadcaster
.addSAXEventKeeperStatusChangeListener(this);
325 boolean rc
= !m_bSAXEventKeeperIncluded
;
328 * changes the export document handler.
330 m_bSAXEventKeeperIncluded
=true;
337 * finds key element or referenced element for a signature.
339 private void findKeyOrReference(SecurityEntity signatureEntity
, String uriStr
, boolean isFindingKey
)
343 while (i
<m_vUnsolvedReferenceIds
.size())
345 String id
= (String
)m_vUnsolvedReferenceIds
.elementAt(i
);
347 if (id
.equals(uriStr
))
349 int refNum
= ((Integer
)m_vUnsolvedReferenceRefNum
.elementAt(i
)).intValue();
350 int keeperId
= ((Integer
)m_vUnsolvedReferencedKeeperIds
.elementAt(i
)).intValue();
355 * clones a new ElementCollector for the key element.
357 int cloneKeeperId
= m_xSAXEventKeeper
.cloneElementCollector(
360 (ElementMarkPriority
.BEFOREMODIFY
):(ElementMarkPriority
.AFTERMODIFY
));
363 * notifies the key keeper id.
365 signatureEntity
.setKeyId(cloneKeeperId
);
368 * sets the security id for the key.
370 m_xSAXEventKeeper
.setSecurityId(cloneKeeperId
, signatureEntity
.getSecurityId());
373 * sets the resolve listener.
375 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
376 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
377 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
378 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
380 signatureEntity
.getReferenceListener());
385 * clones a new ElementCollector for the referenced element.
387 int cloneKeeperId
= m_xSAXEventKeeper
.cloneElementCollector(
390 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
));
393 * sets the security id.
395 m_xSAXEventKeeper
.setSecurityId(cloneKeeperId
, signatureEntity
.getSecurityId());
398 * sets the resolve listener.
400 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
401 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
402 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
403 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(cloneKeeperId
,
404 signatureEntity
.getReferenceListener());
407 XReferenceCollector xReferenceCollector
=
408 (XReferenceCollector
)UnoRuntime
.queryInterface(
409 XReferenceCollector
.class, signatureEntity
.getReferenceListener());
410 xReferenceCollector
.setReferenceId(cloneKeeperId
);
412 catch( com
.sun
.star
.uno
.Exception e
)
419 * if this unsolved reference reaches its max reference number, remove this reference
425 m_xSAXEventKeeper
.removeElementCollector(keeperId
);
426 m_vUnsolvedReferenceIds
.remove(i
);
427 m_vUnsolvedReferencedKeeperIds
.remove(i
);
428 m_vUnsolvedReferenceRefNum
.remove(i
);
432 m_vUnsolvedReferenceRefNum
.setElementAt(new Integer(refNum
),(i
));
437 * If it is find a key, then no further search is needed, one
438 * signature has one key at most.
453 * checks whether a startElement event represents any security related information.
454 * return true if this event can't be forwarded into the SAX chain.
456 private boolean checkSecurityElement(String localName
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
)
460 if (localName
.equals("Signature"))
462 * this element is a Signature element.
465 SignatureEntity signatureEntity
= new SignatureEntity(
469 m_xXMLSecurityContext
,
472 m_xRemoteServiceManager
,
475 m_signatureList
.add(signatureEntity
);
476 m_currentPath
.push(signatureEntity
);
478 else if(localName
.equals("Reference"))
480 if (!m_currentPath
.empty())
482 Object signedInfo
= m_currentPath
.pop();
484 if (!m_currentPath
.empty())
486 Object objSignature
= m_currentPath
.peek();
488 if ((objSignature
instanceof SignatureEntity
) && signedInfo
.toString().equals("SignedInfo"))
490 * this element is a Reference element in a signature.
493 String uriStr
= xattribs
.getValueByName("URI");
495 if (uriStr
.charAt(0) == '#')
497 uriStr
= uriStr
.substring(1);
498 SignatureEntity signatureEntity
= (SignatureEntity
)objSignature
;
500 if (uriStr
!= null && uriStr
.length()>0)
502 signatureEntity
.addReferenceId(uriStr
);
503 findKeyOrReference(signatureEntity
, uriStr
, false);
508 m_currentPath
.push(signedInfo
);
510 m_currentPath
.push(localName
);
512 else if(localName
.equals("KeyValue") ||
513 localName
.equals("KeyName") ||
514 localName
.equals("X509Data") ||
515 localName
.equals("EncryptedKey"))
517 if (!m_currentPath
.empty())
519 Object keyInfo
= m_currentPath
.pop();
521 if (!m_currentPath
.empty())
523 Object objSorE
= m_currentPath
.peek();
525 if ((objSorE
instanceof SignatureEntity
) && keyInfo
.toString().equals("KeyInfo"))
527 * this element is the key element of a signature.
530 SignatureEntity signatureEntity
= (SignatureEntity
)objSorE
;
531 signatureEntity
.setKeyId(0);
533 else if ((objSorE
instanceof EncryptionEntity
) && keyInfo
.toString().equals("KeyInfo"))
535 * this element is the key element of an encryption.
538 EncryptionEntity theEncryption
= (EncryptionEntity
)objSorE
;
539 theEncryption
.setKeyId(0);
542 m_currentPath
.push(keyInfo
);
545 m_currentPath
.push(localName
);
547 else if(localName
.equals("RetrievalMethod"))
549 if (!m_currentPath
.empty())
551 Object keyInfo
= m_currentPath
.pop();
553 if (!m_currentPath
.empty())
555 Object objSorE
= m_currentPath
.peek();
557 if ((objSorE
instanceof SignatureEntity
) && keyInfo
.toString().equals("KeyInfo"))
559 * this element is the RetrievalMethod element in a signature,
560 * which will include the key uri of this signature.
563 String uriStr
= xattribs
.getValueByName("URI");
564 SignatureEntity signatureEntity
= (SignatureEntity
)objSorE
;
566 if (uriStr
!= null && uriStr
.length()>0)
568 signatureEntity
.setKeyURI(uriStr
);
569 findKeyOrReference(signatureEntity
,uriStr
, true);
572 else if ((objSorE
instanceof EncryptionEntity
) && keyInfo
.toString().equals("KeyInfo"))
574 * this element is the RetrievalMethod element in an encryption,
575 * which will include the key uri of this encryption.
578 String uriStr
= xattribs
.getValueByName("URI");
579 EncryptionEntity theEncryption
= (EncryptionEntity
)objSorE
;
581 if (uriStr
!= null && uriStr
.length()>0)
583 theEncryption
.setKeyURI(uriStr
);
584 findKeyOrReference(theEncryption
, uriStr
, true);
588 m_currentPath
.push(keyInfo
);
590 m_currentPath
.push(localName
);
592 else if (localName
.equals("EncryptedData")) /* || localName.equals("EncryptedKey")) */
594 * this element is an Encryption element.
597 EncryptionEntity theEncryption
= new EncryptionEntity(
601 m_xXMLSecurityContext
,
604 m_xRemoteServiceManager
,
607 m_encryptionList
.add(theEncryption
);
611 m_currentPath
.push(theEncryption
);
615 String uriStr
= xattribs
.getValueByName("keyURI");
616 if (uriStr
!= null && uriStr
.length()>0)
618 theEncryption
.setKeyURI(uriStr
);
619 findKeyOrReference(theEncryption
,uriStr
, true);
623 theEncryption
.setKeyId(0);
631 * not a security related element.
634 m_currentPath
.push(localName
);
641 * checks whether a startElement event is referenced by any security entity.
643 private void checkReference(String localName
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
, String id
)
645 String refNumStr
= xattribs
.getValueByName("refNum");
647 if ( m_bIsEncryptionTarget
)
649 m_EncryptionForTarget
.setReference(m_bIsExporting
);
650 m_bIsEncryptionTarget
= false;
653 if (id
!= null && id
.length()>0 )
655 * only if this element has id attribute, then it can be referenced by
660 * if this element has an "refNum" attribute, then the value will be
661 * the max referencing number on this element, otherwise, set the max
662 * referencing number to 999.
666 if (refNumStr
!= null && refNumStr
.length()>0 )
668 refNum
= new Integer(refNumStr
).intValue();
674 * searches the signature list to check whether any sigture has
675 * reference on this element.
677 length
= m_signatureList
.size();
678 for (int i
=0; i
<length
; ++i
)
680 SignatureEntity signatureEntity
= (SignatureEntity
)m_signatureList
.elementAt(i
);
682 if (signatureEntity
.setReference(id
, m_bIsExporting
))
687 if (signatureEntity
.setKey(id
, m_bIsExporting
))
694 * searches the encryption list for reference.
696 length
= m_encryptionList
.size();
697 for (int i
=0; i
<length
; ++i
)
699 EncryptionEntity theEncryption
= (EncryptionEntity
)m_encryptionList
.elementAt(i
);
701 if (theEncryption
.setKey(id
, m_bIsExporting
))
708 * if the max referencing number is not reached, then add this element
709 * into the unsolved reference list.
715 if (localName
.equals("EncryptedKey"))
717 keeperId
= m_xSAXEventKeeper
.addSecurityElementCollector(
719 (ElementMarkPriority
.BEFOREMODIFY
):(ElementMarkPriority
.AFTERMODIFY
),
724 keeperId
= m_xSAXEventKeeper
.addSecurityElementCollector(
726 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
),
730 m_vUnsolvedReferenceIds
.add(id
);
731 m_vUnsolvedReferencedKeeperIds
.add(new Integer(keeperId
));
732 m_vUnsolvedReferenceRefNum
.add(new Integer(refNum
));
738 * configures the output handler.
740 private void setOutputHandler(XDocumentHandler handler
)
742 m_xOutputHandler
= handler
;
747 /**************************************************************************************
749 **************************************************************************************/
752 * methods used to transfer unsolved reference information.
754 protected Vector
getUnsolvedReferenceIds()
756 return m_vUnsolvedReferenceIds
;
759 protected Vector
getUnsolvedReferenceKeeperIds()
761 return m_vUnsolvedReferencedKeeperIds
;
764 protected Vector
getUnsolvedReferenceRefNum()
766 return m_vUnsolvedReferenceRefNum
;
769 protected String
getBufferNodeTreeInformation()
771 if (m_xSAXEventKeeper
!= null)
773 return m_xSAXEventKeeper
.printBufferNodeTree();
781 protected void getDocument(XDocumentHandler handler
)
783 if (m_xXMLDocumentWrapper
!= null)
787 m_xXMLDocumentWrapper
.getTree(handler
);
789 catch(SAXException e
)
796 protected void endMission()
798 while (m_signatureList
.size()>0 || m_encryptionList
.size()>0)
800 if (m_signatureList
.size()>0)
802 SignatureEntity signatureEntity
= (SignatureEntity
)m_signatureList
.elementAt(0);
803 m_signatureList
.remove(0);
804 signatureEntity
.endMission();
806 else if (m_encryptionList
.size()>0)
808 EncryptionEntity theEncryption
= (EncryptionEntity
)m_encryptionList
.elementAt(0);
809 m_encryptionList
.remove(0);
810 theEncryption
.endMission();
814 while (m_vUnsolvedReferenceIds
.size()>0)
816 int keeperId
= ((Integer
)m_vUnsolvedReferencedKeeperIds
.elementAt(0)).intValue();
817 m_xSAXEventKeeper
.removeElementCollector(keeperId
);
818 m_vUnsolvedReferenceIds
.remove(0);
819 m_vUnsolvedReferencedKeeperIds
.remove(0);
820 m_vUnsolvedReferenceRefNum
.remove(0);
823 m_xSAXEventKeeper
.setNextHandler(null);
825 XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster
=
826 (XSAXEventKeeperStatusChangeBroadcaster
)UnoRuntime
.queryInterface(
827 XSAXEventKeeperStatusChangeBroadcaster
.class, m_xSAXEventKeeper
);
828 xSaxEventKeeperStatusChangeBroadcaster
.addSAXEventKeeperStatusChangeListener(null);
830 m_xSAXEventKeeper
= null;
831 m_xXMLDocumentWrapper
= null;
832 m_xOutputHandler
= null;
833 m_xXMLSecurityContext
= null;
834 m_xXMLSignature
= null;
835 m_xXMLEncryption
= null;
837 m_xExportHandler
= null;
838 m_parsingThread
.setHandler(null);
841 /**************************************************************************************
843 **************************************************************************************/
848 public void startDocument()
851 m_xExportHandler
.startDocument();
853 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
860 public void endDocument()
863 m_xExportHandler
.endDocument();
865 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
871 public void startElement (String str
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
)
874 String idAttr
= xattribs
.getValueByName("id");
877 idAttr
= xattribs
.getValueByName("Id");
880 boolean hasIdAttr
= (idAttr
!= null && idAttr
.length()>0 );
881 boolean needResend
= false;
884 (str
.equals("Signature")||str
.equals("EncryptedData")))/* || str.equals("EncryptedKey"))) */
886 if (foundSecurityRelated() && !m_bIsExporting
)
892 boolean suppressToNext
= checkSecurityElement(str
, xattribs
);
894 checkReference(str
, xattribs
, idAttr
);
898 m_xSAXEventKeeper
.setNextHandler(null);
900 XDocumentHandler saxEventKeeperHandler
=
901 (XDocumentHandler
)UnoRuntime
.queryInterface(
902 XDocumentHandler
.class, m_xSAXEventKeeper
);
903 saxEventKeeperHandler
.startElement(str
, xattribs
);
904 m_xSAXEventKeeper
.setNextHandler((XDocumentHandler
)this);
909 m_xExportHandler
.startElement(str
, xattribs
);
912 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
918 public void endElement(String str
)
920 if (!m_currentPath
.empty())
922 Object obj
= m_currentPath
.pop();
924 if (obj
.toString().equals("SignedInfo"))
926 if (!m_currentPath
.empty())
928 Object objSignature
= m_currentPath
.peek();
929 if (objSignature
!= null && objSignature
instanceof SignatureEntity
)
931 ((SignatureEntity
)objSignature
).setReferenceNumber();
935 else if (obj
instanceof EncryptionEntity
)
937 m_bIsEncryptionTarget
= true;
938 m_EncryptionForTarget
= (EncryptionEntity
)obj
;
944 m_xExportHandler
.endElement(str
);
946 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
952 public void characters(String str
)
955 m_xExportHandler
.characters(str
);
957 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
963 public void ignorableWhitespace(String str
)
967 public void processingInstruction(String aTarget
, String aData
)
970 m_xExportHandler
.processingInstruction(aTarget
, aData
);
972 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
978 public void setDocumentLocator (com
.sun
.star
.xml
.sax
.XLocator xLocator
)
979 throws com
.sun
.star
.xml
.sax
.SAXException
985 * XSignatureCreationResultListener
987 public void signatureCreated(int securityId
, SecurityOperationStatus creationResult
)
989 String message
= new String();
990 message
+= "A Signature is created:";
991 message
+= "\nSecurity Id = "+securityId
;
992 message
+= "\nCreation result = "+((creationResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
994 m_testTool
.showMessage("Message from : SignatureCreator\n\n"+message
+"\n ");
998 * XSignatureVerifyResultListener
1000 public void signatureVerified(int securityId
, SecurityOperationStatus verifyResult
)
1002 String message
= new String();
1003 message
+= "A Signature is verified:";
1004 message
+= "\nSecurity Id = "+securityId
;
1005 message
+= "\nVerify result = "+((verifyResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1007 m_testTool
.showMessage("Message from : SignatureVerifier\n\n"+message
+"\n ");
1011 * XEncryptionResultListener
1013 public void encrypted(int securityId
, SecurityOperationStatus encryptionResult
)
1015 String message
= new String();
1016 message
+= "An EncryptedData is encrypted:";
1017 message
+= "\nSecurity Id = "+securityId
;
1018 message
+= "\nEncrypt result = "+((encryptionResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1020 m_testTool
.showMessage("Message from : Encryptor\n\n"+message
+"\n ");
1024 * XDecryptionResultListener methods
1026 public void decrypted(int securityId
, SecurityOperationStatus decryptionResult
)
1028 String message
= new String();
1029 message
+= "An EncryptedData is decrypted:";
1030 message
+= "\nSecurity Id = "+securityId
;
1031 message
+= "\nDecrypt result = "+((decryptionResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1033 m_testTool
.showMessage("Message from : Decryptor\n\n"+message
+"\n ");
1037 * XSAXEventKeeperStatusChangeListener methods
1039 public void blockingStatusChanged(boolean isBlocking
)
1041 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1042 (isBlocking?
"The SAX event stream is blocked.":"The SAX event stream is unblocked.")+
1045 this.m_bIsBlocking
= isBlocking
;
1048 public void collectionStatusChanged(boolean isInsideCollectedElement
)
1050 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1051 (isInsideCollectedElement?
"Begin to buffer data ...":"End of data bufferring.")+
1055 this.m_bIsInsideCollectedElement = isInsideCollectedElement;
1057 if ( !m_bIsInsideCollectedElement && !m_bIsBlocking)
1059 m_bSAXEventKeeperIncluded = false;
1063 m_bSAXEventKeeperIncluded = true;
1069 public void bufferStatusChanged(boolean isBufferEmpty
)
1071 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1072 (isBufferEmpty?
"All bufferred data are released, the SAXEventKeeper is destroyed.":"buffer data appears.")+
1077 m_xXMLDocumentWrapper = null;
1078 m_xSAXEventKeeper = null;
1079 m_bSAXEventKeeperIncluded = false;