Changeset 687 for TI12-security
- Timestamp:
- 22/03/06 11:36:47 (15 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 4 added
- 4 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/NDG/Session.py
r686 r687 52 52 # Use to pipe output from ZSI ServiceProxy 53 53 from cStringIO import StringIO 54 55 # Use in SessionMgr __redirectAuthorisationReq to store Public key 56 import tempfile 57 54 58 55 59 #_____________________________________________________________________________ … … 989 993 # Retrieve the public key from the URI 990 994 try: 991 userSessMgrPubKey = NamedTemporaryFile()995 userSessMgrPubKey = tempfile.NamedTemporaryFile() 992 996 (fileName, httpResp) = urllib.urlretrieve(userSessMgrPubKeyURI, 993 997 userSessMgrPubKey.name) -
TI12-security/trunk/python/NDG/SessionClient.py
r686 r687 22 22 from X509 import * 23 23 from SessionMgrIO import * 24 25 import tempfile 24 26 25 27 … … 62 64 self.__smPubKeyFilePath = None 63 65 self.__smPubKeyURI = None 66 self.__clntPubKeyFilePath = None 64 67 65 68 if smWSDL: … … 92 95 self.__smWSDL = smWSDL 93 96 94 smWSDL = property(fset=__setSMwsdl, 95 doc="Set Session Manager WSDL URI") 97 smWSDL = property(fset=__setSMwsdl, doc="Set Session Manager WSDL URI") 96 98 97 99 … … 132 134 133 135 self.__clntPubKeyFilePath = clntPubKeyFilePath 134 self.__clntPubKeyFilePath = None135 136 136 137 clntPubKeyFilePath = property(fset=__setClntPubKeyFilePath, 137 138 doc="File path for client public key") 138 139 139 140 141 #_________________________________________________________________________ 142 def __retrieveSMpubKeyFromURI(self): 143 """Retrieve the public key from the URI""" 144 145 # Don't proceed unless URI was set - user may have set public key via 146 # smPubKeyFilePath instead 147 if self.__smPubKeyURI is None: 148 return None 149 150 try: 151 smPubKey = tempfile.NamedTemporaryFile() 152 (fileName, httpResp) = urllib.urlretrieve(smMgrPubKeyURI, 153 smMgrPubKey.name) 154 except Exception, e: 155 raise SessionClientError("Error retrieving Session Manager "+\ 156 "public key from \"%s\": %s" % \ 157 (self.__smPubkeyURI, str(e))) 158 159 # Expecting plain text format for returned public key file 160 # 404 error would come back as 'text/html' 161 if 'text/plain' not in httpResp['Content-type']: 162 raise SessionClientError("Error retrieving Session Manager "+\ 163 "public key from \"%s\": expecting \"plain/text\"" % \ 164 self.__smPubkeyURI) 165 166 # Return tempfile object as otherwise it will go out of scope and the 167 # temporary file will be deleted 168 return smPubKey 169 170 140 171 #_________________________________________________________________________ 141 172 def serviceProxy(self, smWSDL=None): … … 171 202 except Exception, e: 172 203 raise SessionClientError("Pass-phrase not defined: " + str(e)) 204 205 206 # If Public key was set by URI, retrieve otherwise get from 207 # smPubKeyFilePath 208 smPubKeyTmpFile = self.__retrieveSMpubKeyFromURI() 209 if smPubKeyTmpFile: 210 smPubKeyFilePath = smPubKeyTmpFile.name 211 else: 212 smPubKeyFilePath = self.__smPubKeyFilePath 173 213 174 214 … … 225 265 except Exception, e: 226 266 raise SessionClientError("Pass-phrase not defined: " + str(e)) 227 228 267 268 269 # If Public key was set by URI, retrieve otherwise get from 270 # smPubKeyFilePath 271 smPubKeyTmpFile = self.__retrieveSMpubKeyFromURI() 272 if smPubKeyTmpFile: 273 smPubKeyFilePath = smPubKeyTmpFile.name 274 else: 275 smPubKeyFilePath = self.__smPubKeyFilePath 276 277 229 278 # Make connection 230 279 try: … … 234 283 createServerSess=createServerSess, 235 284 encrCert=self.__clntPubKeyFilePath, 236 encrPubKeyFilePath=s elf.__smPubKeyFilePath)285 encrPubKeyFilePath=smPubKeyFilePath) 237 286 238 287 # Pass encrypted request … … 299 348 raise SessionClientError("Error parsing session cookie: " + \ 300 349 str(e)) 350 351 352 # If Public key was set by URI, retrieve otherwise get from 353 # smPubKeyFilePath 354 smPubKeyTmpFile = self.__retrieveSMpubKeyFromURI() 355 if smPubKeyTmpFile: 356 smPubKeyFilePath = smPubKeyTmpFile.name 357 else: 358 smPubKeyFilePath = self.__smPubKeyFilePath 359 301 360 302 361 # Make authorisation request … … 313 372 extTrustedHostList=extTrustedHostList, 314 373 encrCert=self.__clntPubKeyFilePath, 315 encrPubKeyFilePath=s elf.__smPubKeyFilePath)374 encrPubKeyFilePath=smPubKeyFilePath) 316 375 317 376 resp = self.__smSrv.reqAuthorisation(authorisationReq=authReq()) -
TI12-security/trunk/python/ndgSessionClient.py
r686 r687 26 26 #_____________________________________________________________________________ 27 27 def setSoapDebug(option, optStr, value, parser): 28 """ Callback function for parser"""28 """Parser Callback function for enabling SOAP debug output""" 29 29 parser.values.soapDebug = sys.stderr 30 30 … … 32 32 #_____________________________________________________________________________ 33 33 def setSessCookie(option, optStr, value, parser): 34 """Callback function for parser""" 34 """Parser Callback function for reading session cookie from command line 35 """ 35 36 try: 36 37 parser.values.sessCookie = SimpleCookie(open(value).read().strip()) 38 37 39 except IOError, (errNo, errMsg): 38 40 raise optparse.OptionValueError(\ 39 41 "Reading cookie from file \"%s\": %s" % (value, errMsg)) 40 42 41 43 except Exception, e: 42 44 raise optparse.OptionValueError(\ 43 45 "Reading cookie from file \"%s\": %s" % (value, str(e))) 44 46 47 48 #_____________________________________________________________________________ 49 def setSessCookieFromStdin(option, optStr, value, parser): 50 """Parser Callback function for reading cookie from stdin""" 51 try: 52 # Read from standard input 53 parser.values.sessCookie = SimpleCookie(sys.stdin.read().strip()) 54 55 except KeyboardInterrupt: 56 raise optparse.OptionValueError(\ 57 "option \"%s\": expecting cookie set from stdin" % optStr) 58 59 except Exception, e: 60 raise optparse.OptionValueError(\ 61 "option %s: Reading cookie from file \"%s\": %s" % \ 62 (optStr, value, str(e))) 63 64 45 65 #_____________________________________________________________________________ 46 66 if __name__ == '__main__': … … 118 138 """Session cookie for --req-autho/-r call. This is returned from a previous 119 139 connect call (-c USERNAME/--connect=USERNAME). Note that connect and request 120 authoirsati nocalls can be combined. In this case, this arg is not needed as140 authoirsation calls can be combined. In this case, this arg is not needed as 121 141 the cookie is passed directly from the connect call output to the 122 142 authorisation request e.g. ... -c username -r -s "http://..." -a … … 125 145 parser.add_option("-e", 126 146 "--pass-cookie-from-stdin", 127 action=" store_true",128 dest="bCookieFromStdin",129 de fault=False,130 help=" Takesession cookie from stdin.")147 action="callback", 148 callback=setSessCookieFromStdin, 149 dest="sessCookie", 150 help="Read session cookie from stdin.") 131 151 132 152 parser.add_option("-a", -
TI12-security/trunk/python/sessionMgrProperties.xml
r686 r687 5 5 <keyFile></keyFile> 6 6 <keyPPhrase></keyPPhrase> 7 <sess ionMgrEncrKey></sessionMgrEncrKey>8 <sess ionMgrWSDLuri></sessionMgrWSDLuri>9 <sess ionMgrPubKeyURI></sessionMgrPubKeyURI>7 <sessMgrEncrKey></sessMgrEncrKey> 8 <sessMgrWSDLuri></sessMgrWSDLuri> 9 <sessMgrPubKeyURI></sessMgrPubKeyURI> 10 10 <cookieDomain></cookieDomain> 11 11 <myProxyProp>
Note: See TracChangeset
for help on using the changeset viewer.