Changeset 4052


Ignore:
Timestamp:
18/07/08 16:00:44 (11 years ago)
Author:
pjkersha
Message:

Successfully tested echo client (ndg.security.test.wsSecurity.client) with DOM based C14N vs. echo server running ElementTree C14N (security/python/Tests/etreewss/server)

  • fixed _verifyTimestamp in ndg.security.common.wsSecurity.SignatureHandler?
  • Fixed logging for ndg.security.test.wsSecurity.client.echoClientTest
Location:
TI12-security/trunk/python
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/Tests/etreewss/server/echoServer.cfg

    r4024 r4052  
    99[setUp] 
    1010hostname = localhost 
    11 #port = 7000 
    12 port = 7100 
     11port = 7000 
     12#port = 7100 
    1313path = /Echo 
    1414wsseCfgFilePath = $NDGSEC_WSSESRV_UNITTEST_DIR/wssecurity.cfg 
  • TI12-security/trunk/python/ndg.security.common/ndg/security/common/wsSecurity.py

    r3897 r4052  
    758758         
    759759 
    760     def _verifyTimeStamp(self, parsedSOAP, ctxt): 
     760    def _verifyTimeStamp(self, parsedSOAP, ctxt, timestampMustBeSet=False): 
    761761        """Call from verify to check timestamp if found.   
    762762         
     
    770770 
    771771        try: 
    772             timestampNode = xpath.Evaluate('//wsse:Timestamp', 
     772            timestampNode = xpath.Evaluate('//wsu:Timestamp', 
    773773                                           contextNode=parsedSOAP.dom, 
    774774                                           context=ctxt)[0] 
    775775        except: 
    776             log.warning("Verifying message - No timestamp element found") 
    777             return 
     776            msg = "Verifying message - No timestamp element found" 
     777            if timestampMustBeSet: 
     778                raise TimestampError(msg) 
     779            else: 
     780                log.warning(msg) 
     781                return 
    778782         
    779783        # Time now  
    780784        dtNow = datetime.utcnow() 
    781          
    782         createdNode = timestampNode.getElementsByTagName("Created") 
    783          
     785        import pdb;pdb.set_trace() 
     786        try: 
     787            createdNodeText = getElements(timestampNode, "Created")[0].\ 
     788                                    childNodes[0].nodeValue 
     789        except IndexError: 
     790            raise TimestampError("Verifying message - No Created timestamp " 
     791                                 "sub-element found") 
     792             
    784793        # Workaround for fractions of second 
    785794        try: 
    786             [createdDateTime, createdSecFraction]=createdNode.nodeValue.split() 
     795            createdDateTime, strCreatedSecFraction = createdNodeText.split('.') 
     796                                             
     797            strCreatedSecFraction = strCreatedSecFraction.split('Z')[0] 
     798            createdExp = -int(len(strCreatedSecFraction)) 
     799            createdSecFraction = int(strCreatedSecFraction) * 10 ** createdExp 
     800 
    787801        except ValueError, e: 
    788802            raise ValueError("Parsing timestamp Created element: %s" % e) 
    789803         
    790804        dtCreated = datetime.strptime(createdDateTime, '%Y-%m-%dT%H:%M:%S') 
    791         dtCreated += timedelta(seconds=int(createdSecFraction)) 
     805        dtCreated += timedelta(seconds=createdSecFraction) 
    792806        if dtCreated >= dtNow: 
    793807            raise TimestampError(\ 
     
    795809                (dtCreated, dtNow)) 
    796810         
    797         expiresNode = timestampNode.getElementsByTagName("Expires") 
    798         if expiresNode is None: 
    799             log.warning(\ 
    800                 "Verifying message - No Expires element found in Timestamp") 
    801             return 
    802  
    803811        try: 
    804             [expiresDateTime, expiresSecFraction]=expiresNode.nodeValue.split() 
     812            expiresNodeText = getElements(timestampNode, "Expires")[0].\ 
     813                                    childNodes[0].nodeValue 
     814        except IndexError: 
     815            raise TimestampError("Verifying message - No Expires element " 
     816                                 "found in Timestamp") 
     817 
     818        try: 
     819            expiryDateTime, strExpirySecFraction = expiresNodeText.split('.') 
     820             
     821            strExpirySecFraction = strExpirySecFraction.split('Z')[0] 
     822            expiryExp = -int(len(strExpirySecFraction)) 
     823            expirySecFraction = int(strExpirySecFraction) * 10 ** expiryExp 
     824 
    805825        except ValueError, e: 
    806826            raise ValueError("Parsing timestamp Expires element: %s" % e) 
    807827         
    808         dtCreated = datetime.strptime(expiresDateTime, '%Y-%m-%dT%H:%M:%S') 
    809         dtCreated += timedelta(seconds=int(createdSecFraction)) 
    810         if dtExpiry > dtNow: 
     828        dtExpiry = datetime.strptime(expiryDateTime, '%Y-%m-%dT%H:%M:%S') 
     829        dtExpiry += timedelta(seconds=expirySecFraction) 
     830        if dtExpiry < dtNow: 
    811831            raise TimestampError(\ 
    812832                "Timestamp expiry time %s is after the current time %s" % \ 
  • TI12-security/trunk/python/ndg.security.common/ndg/security/common/wssecurity/etree.py

    r4051 r4052  
    836836                                         namespaces=self._processorNSs) 
    837837        if expiresElem is None: 
    838             raise TimestampError(\ 
    839                 "Verifying message - No Expires element found in Timestamp") 
    840             return 
     838            raise TimestampError("Verifying message - No Expires element " 
     839                                 "found in Timestamp") 
    841840 
    842841        try: 
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/echoClientTest.py

    r3652 r4052  
    1818from os.path import join as jnPath 
    1919mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file) 
     20 
     21import logging 
     22logging.basicConfig(level=logging.DEBUG) 
    2023 
    2124class EchoClientTestCase(unittest.TestCase): 
Note: See TracChangeset for help on using the changeset viewer.