Changeset 2080 for TI12-security
- Timestamp:
- 31/01/07 10:15:32 (13 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/CredWallet.py
r2079 r2080 27 27 aaImportError = True 28 28 try: 29 from ndg.security.common.AttAuthority import AttAuthorityClient, \ 30 AttAuthorityClientError 29 # AttAuthority client package resides with CredWallet module in 30 # ndg.security.common 31 from AttAuthority import AttAuthorityClient, AttAuthorityClientError 31 32 aaImportError = False 32 33 … … 159 160 """Volatile store of user credentials associated with a user session""" 160 161 162 __metaclass__ = _MetaCredWallet 163 161 164 def __init__(self, 162 165 proxyCert, 163 166 proxyPriKey, 164 167 userCert, 168 aaURI=None, 169 aaPropFilePath=None, 165 170 caCertFilePath=None, 166 171 credRepos=None, … … 180 185 @param userCert: X.509 cert for issuer of proxy 181 186 187 @type aaURI: string 188 @keyword aaURI: URI of Attribute Authority to make requests to. 189 Setting this ALSO creates an AttAuthorityClient instance 190 self.__aaClnt. - See aaURI property for details. 191 192 @type aaPropFilePath: string 193 @keyword aaPropFilePath: properties file path for an Attribute 194 Authority to make requests to. Setting this ALSO creates an 195 AttAuthority instance self.__aa running locally. - See aa property 196 for details. aaURI takes precedence over this keyword i.e. if an 197 aaURI has been set, then calls are made to the AA web service at this 198 location rather to any self.__aa running locally. 199 182 200 @type caCertFilePath: string 183 201 @keyword caCertFilePath: Certificate Authority's certificate - used in … … 215 233 self.__setUserCert(userCert) 216 234 235 self.__setAAuri(aaURI) 217 236 self.__setCAcertFilePath(caCertFilePath) 218 237 … … 401 420 402 421 #_________________________________________________________________________ 422 def __setAAuri(self, aaURI): 423 """Set property method for Attribute Authority Web Service URI to 424 connect to. This method ALSO SETS UP THE CLIENT INTERFACE 425 426 @type aaURI: string 427 @param aaURI: Attribute Authority Web Service URI. Set to None to 428 initialise. Set to a URI to instantiate a new AA client""" 429 if aaURI is None: 430 self.__aaClnt = None 431 return 432 433 self.__aaClnt = AttAuthorityClient(uri=aaURI, 434 signingCert=self.__proxyCert, 435 signingPriKey=self.__proxyPriKey) 436 437 aaURI = property(fset=__setAAuri, 438 doc="AA URI - setting also sets up AttAuthorityClient instance!") 439 440 441 #_________________________________________________________________________ 442 def __getAAclnt(self): 443 """Get property method for Attribute Authority Web Service client 444 instance. Use aaURI propert to set up aaClnt 445 446 @type aaClnt: AttAuthorityClient 447 @param aaClnt: Attribute Authority Web Service client instance""" 448 return self.__aaClnt 449 450 aaClnt = property(fget=__getAAclnt, doc="AA web service client instance") 451 452 453 #_________________________________________________________________________ 454 def __setAApropFilePath(self, aaPropFilePath): 455 """Set property method for the properties file of a local 456 Attribute Authority. This method ALSO SETS UP THE LOCAL Attribute 457 Authority object to retrieve ACs from. the property aaURI takes 458 precedence: if an aaURI is set then it assumed that an Attribute 459 Authority will be connected to via a web service call 460 461 @type aaPropFilePath: string 462 @param aaPropFilePath: Attribute Authority properties file. Setting 463 this instantiates a new AA locally""" 464 if aaPropFilePath is None: 465 self.__aa = None 466 return 467 468 # Make a new attribute authority instance 469 self.__aa = AttAuthority(propFilePath=aaPropFilePath) 470 471 aaPropFilePath = property(fset=__setAApropFilePath, 472 doc="AA properties file path - setting this also sets up an AA locally!") 473 474 475 #_________________________________________________________________________ 476 def __getAA(self): 477 """Get property method for Attribute Authority Web Service client 478 instance. Use aaURI propert to set up aaClnt 479 480 @type aaClnt: AttAuthorityClient 481 @param aaClnt: Attribute Authority Web Service client instance""" 482 return self.__aaClnt 483 484 aa = property(fget=__getAA, doc="Attribute Authority instance") 485 486 487 #_________________________________________________________________________ 403 488 def isValid(self, **x509CertKeys): 404 """Check wallet's proxy cert. If expired return False""" 489 """Check wallet's proxy cert. If expired return False 490 491 @type **x509CertKeys: dict 492 @param **x509CertKeys: keywords applying to 493 ndg.security.common.X509.X509Cert.isValid method""" 405 494 try: 406 495 return self.__proxyCert.isValidTime(**x509CertKeys) 407 496 408 497 except Exception, e: 409 raise CredWalletError ("Credential Wallet: %s" % e)498 raise CredWalletError, "Credential Wallet: %s" % e 410 499 411 500 … … 413 502 def addCredential(self, attCert, bUpdateCredRepos=True): 414 503 """Add a new attribute certificate to the list of credentials held. 415 Return True if certificate was added otherwise False. - If an 504 505 @type attCert: 506 @param attCert: new attribute Certificate to be added 507 @type bUpdateCredRepos: bool 508 @keyword bUpdateCredRepos: if set to True, and a repository exists it 509 will be updated with the new credentials also 510 511 @rtype: bool 512 @return: True if certificate was added otherwise False. - If an 416 513 existing certificate from the same issuer has a later expiry it will 417 take precence and the new input certificate is ignored. 418 419 attCert: new attribute Certificate to be added 420 bUpdateCredRepos: if set to True, and a repository exisits it will 421 be updated with the new credentials also""" 514 take precence and the new input certificate is ignored.""" 422 515 423 516 # Check input 424 try: 425 if not isinstance(attCert, AttCert): 426 raise CredWalletError(\ 427 "Attribute Certificate must be an AttCert type object") 428 429 except Exception, e: 430 raise CredWalletError, "Attribute Certificate input: %s" % e 431 517 if not isinstance(attCert, AttCert): 518 raise CredWalletError,\ 519 "Attribute Certificate must be an AttCert type object" 432 520 433 521 # Check certificate validity … … 436 524 437 525 except AttCertError, e: 438 raise CredWalletError ("Adding Credential: %s" % e)526 raise CredWalletError, "Adding Credential: %s" % e 439 527 440 528 … … 496 584 def updateCredRepos(self, auditCred=True): 497 585 """Copy over non-persistent credentials held by wallet into the 498 perminent repository.""" 586 perminent repository. 587 588 @type auditCred: bool 589 @keyword auditCred: filter existing credentials in the repository 590 removing invalid ones""" 499 591 500 592 if not self.__credRepos: 501 raise CredWalletError (502 "No Credential Repository has been created for this wallet" )593 raise CredWalletError, \ 594 "No Credential Repository has been created for this wallet" 503 595 504 596 # Filter out invalid certs unless auditCred flag is explicitly set to … … 512 604 self.__credRepos.addCredentials(self.__dn, attCertList) 513 605 606 514 607 #_________________________________________________________________________ 515 def __getAttCert(self, 516 aaPropFilePath=None, 517 aaURI=None, 518 extAttCert=None, 519 bDebug=False): 608 def __getAttCert(self, extAttCert=None): 520 609 521 610 """Wrapper to Attribute Authority attribute certificate request. See … … 528 617 and added into the wallet 529 618 530 @type aaURI: string531 @keyword aaURI: to call as a web service, specify the URI for the532 Attribute Authority.533 534 @type aaPropFilePath: string535 @keyword aaPropFilePath: Altenrative to aaURI - to run on the local536 machine, specify the local Attribute Authority configuration file.537 538 :539 540 619 @type extAttCert: ndg.security.common.AttCert.AttCert 541 620 @keyword extAttCert: an existing Attribute Certificate which can … … 543 622 Attribute Authority""" 544 623 545 if aaURI is not None: 546 try: 547 aaClnt = AttAuthorityClient(uri=aaURI, 548 signingCert=self.__proxyCert, 549 signingPriKey=self.__proxyPriKey) 550 except Exception, e: 551 raise CredWalletError, "Attribute certificate request: %s" % e 552 624 if self.__aaClnt is not None: 553 625 try: 554 attCert = aaClnt.getAttCert(self.__userCert.toString(),555 userAttCert=extAttCert)626 attCert = self.__aaClnt.getAttCert(self.__userCert.toString(), 627 userAttCert=extAttCert) 556 628 except Exception, e: 557 629 raise CredWalletAuthorisationDenied, str(e) … … 565 637 raise CredWalletError, "Attribute Authority Configuration " +\ 566 638 "file path must be a valid string" 567 568 try:569 # Make a new attribute authority instance570 aa = AttAuthority(propFilePath=aaPropFilePath)571 572 except Exception, e:573 raise CredWalletError, "Attribute certificate request: %s" % e574 639 575 640 try: 576 641 # Request a new attribute certificate from the Attribute 577 642 # Authority 578 attCert = aa.getAttCert(userCert=self.__proxyCert,579 userAttCert=extAttCert)643 attCert = self.__aa.getAttCert(userCert=self.__proxyCert, 644 userAttCert=extAttCert) 580 645 581 646 except AttAuthorityAccessDenied, e: … … 609 674 610 675 #_________________________________________________________________________ 611 def getAATrustedHostInfo(self, 676 def getAATrustedHostInfo(self, 612 677 userRole=None, 613 aaURI=None,614 678 aaPropFilePath=None, 615 bDebug=False):679 aaURI=None): 616 680 """Wrapper to Attribute Authority getTrustedHostInfo 617 681 618 userRole: get hosts which have a mapping to this role 619 aaURI|aaPropFilePath: to call as a web service, specify the file 620 path or URI for the Attribute Authority's 621 WSDL. Otherwise, to run on the local machine, 622 specify a local Attribute Authority 623 configuration file.""" 624 625 if aaURI is not None: 682 getAATrustedHostInfo([userRole=r, ][aaPropFilePath=f|aaURI=u]) 683 684 @type userRole: string 685 @keyword userRole: get hosts which have a mapping to this role 686 687 @type aaURI: string 688 @keyword aaURI: to call as a web service, specify the URI for the 689 Attribute Authority. 690 691 @type aaPropFilePath: string 692 @keyword aaPropFilePath: Altenrative to aaURI - to run on the local 693 machine, specify the local Attribute Authority configuration file. 694 """ 695 696 if aaURI: 697 self.__setAAuri(aaURI) 698 elif aaPropFilePath: 699 self.__setAAPropFilePath 700 701 702 if self.__aaClnt is not None: 626 703 # Call Attribute Authority WS 627 704 try: 628 aaClnt = AttAuthorityClient(uri=aaURI, 629 signingCert=self.__proxyCertFilePath, 630 signingPriKey=self.__clntPriKey) 631 632 trustedHostInfo = aaClnt.getTrustedHostInfo(role=userRole) 633 return trustedHostInfo 705 return self.__aaClnt.getTrustedHostInfo(role=userRole) 634 706 635 707 except Exception, e: … … 637 709 "Requesting trusted host information: %s" % str(e) 638 710 639 elif aaPropFilePathis not None:711 elif self.__aa is not None: 640 712 641 713 # Call local based Attribute Authority with settings from the 642 714 # configuration file aaPropFilePath 643 if not instance(aaURI, basestring):644 raise CredWalletError, "Attribute Authority Configuration " +\645 "file path must be a valid string"646 647 715 try: 648 # Make a new attribute authority instance649 aa = AttAuthority(aaPropFilePath)650 651 716 # Request a new attribute certificate from the Attribute 652 717 # Authority 653 return aa.getTrustedHostInfo(role=userRole)718 return self.__aa.getTrustedHostInfo(role=userRole) 654 719 655 720 except Exception, e: … … 768 833 replace it.""" 769 834 770 835 if aaURI: 836 self.__setAAuri(aaURI) 837 elif aaPropFilePath: 838 self.__setAAPropFilePath 839 771 840 if not refreshAttCert and self.__credentials: 772 841 # Refresh flag is not set so it's OK to check for any existing … … 776 845 # Find out the site ID for the target AA by calling AA's host 777 846 # info WS method 778 aaClnt = AttAuthorityClient(uri=aaURI, 779 signingCert=self.__proxyCert, 780 signingPriKey=self.__proxyPriKey) 781 782 hostInfo = aaClnt.getHostInfo() 783 aaName = hostInfo.keys()[0] 847 try: 848 hostInfo = self.__aaClnt.getHostInfo() 849 aaName = hostInfo.keys()[0] 850 except Exception, e: 851 raise CredWalletError, "Getting host info: %s" % e 784 852 785 853 # Look in the wallet for an AC with the same issuer name … … 861 929 # Request Authorisation from Attribute Authority 862 930 try: 863 attCert = self.__getAttCert(aaURI=aaURI, 864 aaPropFilePath=aaPropFilePath, 865 extAttCert=extAttCert) 931 attCert = self.__getAttCert(extAttCert=extAttCert) 866 932 # Access granted 867 933 return attCert … … 897 963 try: 898 964 trustedHostInfo = self.getAATrustedHostInfo(reqRole, 899 aaURI=aaURI,900 965 aaPropFilePath=aaPropFilePath) 901 966 except Exception, e: … … 977 1042 raise authorisationError 978 1043 979 980 #_________________________________________________________________________ 981 def __retrieveURI(self, uri): 982 """Retrieve content from a URI - use to get public key from a 983 remote Attribute Authority 984 985 Nb. If tempFile goes out of scope the temporary file containing the 986 URI content will be deleted also""" 987 988 try: 989 tempFile = tempfile.NamedTemporaryFile() 990 (fileName, httpResp) = urllib.urlretrieve(uri, tempFile.name) 991 except Exception, e: 992 raise CredWalletError, "Error retrieving from URI " + \ 993 "\"%s\": %s" % (uri, str(e)) 994 995 # Expecting plain text format for returned public key file 996 # 404 error would come back as 'text/html' 997 if 'text/plain' not in httpResp['Content-type']: 998 raise CredWalletError, "Error retrieving from URI " + \ 999 "\"%s\": expecting \"plain/text\"" % uri 1000 1001 return tempFile 1002 1044 1003 1045 1004 1046 #_____________________________________________________________________________ -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/SessionMgr/server-config.tac
r2079 r2080 85 85 86 86 87 response.AttCert , response.StatusCode, response.Msg, \88 response.ExtAttCert = result87 response.AttCert = result[0].toString() 88 response.StatusCode, response.Msg, response.ExtAttCert = result[1:] 89 89 90 90 return request, response
Note: See TracChangeset
for help on using the changeset viewer.