Changeset 1999
- Timestamp:
- 13/01/07 15:26:26 (14 years ago)
- Location:
- TI12-security/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/AttAuthority/__init__.py
r1990 r1999 30 30 from AttAuthority_services import AttAuthorityServiceLocator 31 31 from ndg.security.common.wsSecurity import SignatureHandler 32 32 from ndg.security.common.AttCert import AttCertParse 33 33 34 34 #_____________________________________________________________________________ … … 183 183 doc="Password protecting client private key file") 184 184 185 185 186 #_________________________________________________________________________ 186 187 def __getSrvCert(self): … … 211 212 #_________________________________________________________________________ 212 213 def initService(self, uri=None): 213 """Set the WS proxy for the Attribute Authority""" 214 """Set the WS proxy for the Attribute Authority 215 216 @type uri: string 217 @param uri: URI for service to invoke""" 214 218 if uri: 215 219 self.__setURI(uri) … … 237 241 238 242 #_________________________________________________________________________ 239 def getHostInfo(self , clntPriKeyPwd=None):243 def getHostInfo(self): 240 244 """Get host information for the data provider which the 241 245 Attribute Authority represents 242 246 247 @rtype dict 248 @return dictionary of host information for the target attribute 249 authority 243 250 """ 244 251 … … 256 263 257 264 #_________________________________________________________________________ 258 def getTrustedHostInfo(self, role=None , clntPriKeyPwd=None):265 def getTrustedHostInfo(self, role=None): 259 266 """Get list of trusted hosts for an Attribute Authority 260 267 268 @type role: string 269 @param role: get information for trusted hosts that have a mapping to 270 this role 271 272 @rtype dict 273 @return dictionary of trusted hosts indexed by hostname 261 274 """ 262 275 … … 275 288 276 289 #_________________________________________________________________________ 277 def getAttCert(self, 278 proxyCert, 279 userAttCert=None, 280 clntPriKeyPwd=None): 290 def getAttCert(self, proxyCert, userAttCert=None): 281 291 """Request attribute certificate from NDG Attribute Authority Web 282 Service.""" 292 Service. 293 294 @type proxyCert: string 295 @param proxyCert: certificate containing Distinguished Name of user 296 to request an Attribute Certificate for 297 298 @type userAttCert: string / AttCert 299 @param userAttCert: user attribute certificate from which to make a 300 mapped certificate at the target attribute authority. userAttCert 301 must have been issued from a trusted host to the target 302 303 @rtype AttCert 304 @return attribute certificate for user""" 283 305 284 306 … … 286 308 self.__getSrvX509Cert() 287 309 288 310 # Ensure cert is serialized before passing over web service interface 311 if isinstance(userAttCert, AttCert): 312 userAttCert = str(userAttCert) 313 289 314 try: 290 resp = self.__srv.getAttCert(proxyCert) 315 attCert = AttCertParse(self.__srv.getAttCert(proxyCert, 316 userAttCert)) 291 317 292 318 except Exception, e: 293 raise AttAuthorityClientError, "Error: " + str(e) 294 295 return resp 319 raise AttAuthorityClientError, \ 320 "requesting attribute certificate: " + str(e) 321 322 return attCert 296 323 297 324 298 325 #_________________________________________________________________________ 299 326 def getX509Cert(self): 300 """Retrieve the public key of the Attribute Authority""" 327 """Retrieve the X.509 certificate of the Attribute Authority 328 329 @rtype: string 330 @return X.509 certificate for Attribute Authority""" 301 331 302 332 try: -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py
r1967 r1999 15 15 16 16 import unittest 17 import os 18 import sys 17 import os, sys, getpass 18 from ConfigParser import SafeConfigParser 19 19 20 20 from ndg.security.common.AttAuthority import AttAuthorityClient … … 23 23 24 24 def setUp(self): 25 # Session Manager WSDL 26 self.uri = 'http://127.0.0.1:5700/AttributeAuthority' 25 26 configParser = SafeConfigParser() 27 configParser.read("./attAuthorityClientTest.cfg") 28 29 self.cfg = {} 30 for section in configParser.sections(): 31 self.cfg[section] = dict(configParser.items(section)) 27 32 28 33 # Instantiate WS proxy 29 self.clnt = AttAuthorityClient(self.uri, tracefile=sys.stderr) 34 self.clnt = AttAuthorityClient(self.cfg['setUp']['uri'], 35 tracefile=sys.stderr) 30 36 31 37 -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py
r1998 r1999 7 7 NERC Data Grid Project 8 8 9 P J Kershaw 23/02/06 9 @author P J Kershaw 10 11 23/02/06 10 12 11 13 Renamed from SessionClientTest.py 27/0/4/06 12 14 Moved and renamed SessionMgrClientTest.py 23/11/06 13 15 14 Copyright (C) 2006CCLRC & NERC15 16 This software may be distributed under the terms of the Q Public License, 17 version 1.0 or later.16 @copyright (C) 2007 CCLRC & NERC 17 18 @license This software may be distributed under the terms of the Q Public 19 License, version 1.0 or later. 18 20 """ 19 21 import unittest 20 22 import os, sys, getpass 21 23 from ConfigParser import SafeConfigParser 24 22 25 from ndg.security.common.SessionMgr import SessionMgrClient 23 26 from ndg.security.common.SessionCookie import SessionCookie … … 36 39 37 40 tracefile = sys.stderr 41 42 clntPriKeyPwd = self.cfg['setUp'].get('clntprikeypwd') or \ 43 getpass.getpass(prompt="\nsetUp - client private key password: ") 38 44 39 45 # Initialise the Session Manager client connection 40 46 # Omit traceFile keyword to leave out SOAP debug info 41 self.clnt = SessionMgrClient(uri=self.cfg['set up']['smuri'],42 smCertFilePath=self.cfg['set up']['smcertfilepath'],43 clntCertFilePath=self.cfg['set up']['clntcertfilepath'],44 clntPriKeyFilePath=self.cfg['set up']['clntprikeyfilepath'],47 self.clnt = SessionMgrClient(uri=self.cfg['setUp']['smuri'], 48 smCertFilePath=self.cfg['setUp']['smcertfilepath'], 49 clntCertFilePath=self.cfg['setUp']['clntcertfilepath'], 50 clntPriKeyFilePath=self.cfg['setUp']['clntprikeyfilepath'], 45 51 clntPriKeyPwd=clntPriKeyPwd, 46 52 tracefile=tracefile) … … 50 56 51 57 52 def test AddUser(self):58 def test1AddUser(self): 53 59 """Add a new user ID to the MyProxy repository""" 54 60 55 passphrase = self.cfg['test AddUser'].get('passphrase') or \56 getpass.getpass(prompt="\ntest AddUser pass-phrase for new user: ")61 passphrase = self.cfg['test1AddUser'].get('passphrase') or \ 62 getpass.getpass(prompt="\ntest1AddUser pass-phrase for new user: ") 57 63 58 64 # Note the pass-phrase is read from the file tmp. To pass 59 65 # explicitly as a string use the 'pPhrase' keyword instead 60 self.clnt.addUser(self.cfg['test AddUser']['username'],66 self.clnt.addUser(self.cfg['test1AddUser']['username'], 61 67 pPhrase=passphrase) 62 print "Added user '%s'" % self.cfg['test AddUser']['username']63 64 65 def test CookieConnect(self):66 """test CookieConnect: Connect as if acting as a browser client -68 print "Added user '%s'" % self.cfg['test1AddUser']['username'] 69 70 71 def test2CookieConnect(self): 72 """test2CookieConnect: Connect as if acting as a browser client - 67 73 a cookie is returned""" 68 74 69 passphrase = self.cfg['test CookieConnect'].get('passphrase') or \70 getpass.getpass(prompt="\ntest CookieConnect pass-phrase for user: ")75 passphrase = self.cfg['test2CookieConnect'].get('passphrase') or \ 76 getpass.getpass(prompt="\ntest2CookieConnect pass-phrase for user: ") 71 77 72 78 sSessCookie = self.clnt.connect(\ 73 self.cfg['test CookieConnect']['username'],79 self.cfg['test2CookieConnect']['username'], 74 80 pPhrase=passphrase) 75 81 76 82 self.sessCookie = SessionCookie(sSessCookie) 77 83 print "User '%s' connected to Session Manager:\n%s" % \ 78 (self.cfg['test CookieConnect']['username'], sSessCookie)79 80 81 def test ProxyCertConnect(self):82 """test ProxyCertConnect: Connect as a command line client -84 (self.cfg['test2CookieConnect']['username'], sSessCookie) 85 86 87 def test3ProxyCertConnect(self): 88 """test3ProxyCertConnect: Connect as a command line client - 83 89 a proxyCert is returned""" 84 90 85 passphrase = self.cfg['test ProxyCertConnect'].get('passphrase') or \91 passphrase = self.cfg['test3ProxyCertConnect'].get('passphrase') or \ 86 92 getpass.getpass(\ 87 prompt="\ntest ProxyCertConnect pass-phrase for user: ")93 prompt="\ntest3ProxyCertConnect pass-phrase for user: ") 88 94 89 95 self.proxyCert = self.clnt.connect(\ 90 self.cfg['test ProxyCertConnect']['username'],96 self.cfg['test3ProxyCertConnect']['username'], 91 97 pPhrase=passphrase, 92 98 createServerSess=True, 93 99 getCookie=False) 94 100 print "User '%s' connected to Session Manager:\n%s" % \ 95 (self.cfg['test ProxyCertConnect']['username'], self.proxyCert)96 97 98 def test CookieDisconnect(self):99 """test CookieDisconnect: disconnect as if acting as a browser client -101 (self.cfg['test3ProxyCertConnect']['username'], self.proxyCert) 102 103 104 def test4CookieDisconnect(self): 105 """test4CookieDisconnect: disconnect as if acting as a browser client - 100 106 a cookie is returned""" 101 107 102 self.testCookieConnect() 108 print "\n\t" + self.test4CookieDisconnect.__doc__ 109 self.test2CookieConnect() 103 110 104 111 self.clnt.disconnect(sessCookie=str(self.sessCookie)) … … 106 113 107 114 108 def test ProxyCertDisconnect(self):109 """test ProxyCertDisconnect: Connect as a command line client -115 def test5ProxyCertDisconnect(self): 116 """test5ProxyCertDisconnect: Connect as a command line client - 110 117 a proxyCert is returned""" 111 118 112 self.testProxyCertConnect() 119 print "\n\t" + self.test5ProxyCertDisconnect.__doc__ 120 self.test3ProxyCertConnect() 113 121 114 122 self.clnt.disconnect(proxyCert=self.proxyCert) … … 116 124 117 125 118 def test CookieReqAuthorisation(self):119 """test CookieReqAuthorisation: make an authorisation request using126 def test6CookieReqAuthorisation(self): 127 """test6CookieReqAuthorisation: make an authorisation request using 120 128 a cookie as authentication credential""" 121 122 self.testCookieConnect() 129 130 print "\n\t" + self.test6CookieReqAuthorisation.__doc__ 131 self.test2CookieConnect() 123 132 attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ 124 133 sessID=self.sessCookie.sessionID, 125 attAuthorityURI=self.cfg['test CookieReqAuthorisation']['aauri'],134 attAuthorityURI=self.cfg['test6CookieReqAuthorisation']['aauri'], 126 135 encrSessionMgrURI=self.sessCookie.encrSessionMgrURI) 127 136 … … 131 140 132 141 133 def test CookieReqAuthorisationWithExtAttCertList(self):134 """test CookieReqAuthorisation: make an authorisation request using142 def test6aCookieReqAuthorisationWithExtAttCertList(self): 143 """test6CookieReqAuthorisation: make an authorisation request using 135 144 a cookie as authentication credential""" 136 145 137 self.testCookieConnect() 146 print "\n\t" + self.test6aCookieReqAuthorisationWithExtAttCertList.__doc__ 147 self.test2CookieConnect() 138 148 139 149 aaURI = \ 140 self.cfg['test CookieReqAuthorisationWithExtAttCertList']['aauri']150 self.cfg['test6aCookieReqAuthorisationWithExtAttCertList']['aauri'] 141 151 142 152 attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ … … 151 161 152 162 153 def test ProxyCertReqAuthorisation(self):154 """test ProxyCertReqAuthorisation: make an authorisation request using163 def test7ProxyCertReqAuthorisation(self): 164 """test7ProxyCertReqAuthorisation: make an authorisation request using 155 165 a proxy cert as authentication credential""" 156 self.testProxyCertConnect() 166 print "\n\t" + self.test7ProxyCertReqAuthorisation.__doc__ 167 self.test3ProxyCertConnect() 157 168 158 169 # Request an attribute certificate from an Attribute Authority 159 170 # using the proxyCert returned from connect() 160 171 161 aaURI = self.cfg['test ProxyCertReqAuthorisation']['aauri']172 aaURI = self.cfg['test7ProxyCertReqAuthorisation']['aauri'] 162 173 attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ 163 174 proxyCert=self.proxyCert, … … 169 180 170 181 171 def test GetX509Cert(self):172 "test GetX509Cert: return the Session Manager's X.509 Cert."182 def test8GetX509Cert(self): 183 "test8GetX509Cert: return the Session Manager's X.509 Cert." 173 184 cert = self.clnt.getX509Cert() 174 185 … … 182 193 map = map(SessionMgrClientTestCase, 183 194 ( 184 "testAddUser", 185 "testCookieConnect", 186 "testProxyCertConnect", 187 "testCookieDisconnect", 188 "testProxyCertDisconnect", 189 "testCookieReqAuthorisation", 190 "testProxyCertReqAuthorisation", 191 "testGetX509Cert", 195 "test1AddUser", 196 "test2CookieConnect", 197 "test3ProxyCertConnect", 198 "test4CookieDisconnect", 199 "test5ProxyCertDisconnect", 200 "test6CookieReqAuthorisation", 201 "test6aCookieReqAuthorisationWithExtAttCertList", 202 "test7ProxyCertReqAuthorisation", 203 "test8GetX509Cert", 192 204 )) 193 205 unittest.TestSuite.__init__(self, map) -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr/sessionMgrClientTest.cfg
r1998 r1999 22 22 # Password protecting client private key - if omitted it will be prompted for 23 23 # from tty 24 #clntprikeypwd = 24 clntprikeypwd = x 25 25 26 26 clntcertfilepath = ./clntCert.pem 27 27 clntprikeyfilepath = ./clntKey.pem 28 28 29 [test AddUser]29 [test1AddUser] 30 30 username = BugsBunny 31 31 # Comment out to prompt for on tty. 32 32 #passphrase = 33 33 34 [test CookieConnect]34 [test2CookieConnect] 35 35 username = gabriel 36 36 #passphrase = 37 37 38 [test ProxyCertConnect]38 [test3ProxyCertConnect] 39 39 username = gabriel 40 40 #passphrase = 41 41 42 [test CookieReqAuthorisation]42 [test6CookieReqAuthorisation] 43 43 aaURI = https://localhost:5000/AttributeAuthority 44 44 45 [test CookieReqAuthorisationWithExtAttCertList]45 [test6aCookieReqAuthorisationWithExtAttCertList] 46 46 aaURI = https://localhost:5000/AttributeAuthority 47 47 48 [test ProxyCertReqAuthorisation]48 [test7ProxyCertReqAuthorisation] 49 49 aaURI = https://localhost:5000/AttributeAuthority 50 50
Note: See TracChangeset
for help on using the changeset viewer.