Changeset 920
- Timestamp:
- 12/05/06 17:30:41 (15 years ago)
- Location:
- TI12-security/trunk/python/NDG
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/NDG/Log.py
r917 r920 37 37 __dateFmt = '%d %b %Y %H:%M:%S' 38 38 39 # Log file size limit and number of backups saved 40 __maxBytes = 1048576 41 __backUpCnt = 10 42 39 43 def __init__(self, logName='', logFilePath=None, console=False): 40 44 """NDG Logging class … … 70 74 if logFilePath: 71 75 fileLog = RotatingFileHandler(logFilePath, 72 maxBytes= 1048576,73 backupCount= 10)76 maxBytes=self.__maxBytes, 77 backupCount=self.__backUpCnt) 74 78 fileLog.setFormatter(formatter) 75 79 -
TI12-security/trunk/python/NDG/XMLMsg.py
r751 r920 10 10 version 1.0 or later. 11 11 """ 12 13 cvsID = '$Id$'14 12 15 13 # For new line symbol … … 54 52 encrPriKeyFilePath=None, 55 53 encrPriKeyPwd=None, 54 signingKeyFilePath=None, 55 signingKeyPwd=None, 56 signingCertFilePath=None, 57 signatureChkCertFilePath=None, 56 58 xmlVers="1.0", 57 59 xmlEncoding="UTF-8", … … 96 98 # Initialisation for XML Security class used for encryption 97 99 try: 100 if signingCertFilePath: 101 # Add cert to signature 102 certFilePathList = signingCertFilePath 103 104 elif signatureChkCertFilePath: 105 # Check an existing doc using the input cert file 106 certFilePathList = signatureChkCertFilePath 107 else: 108 certFilePathList = None 109 98 110 self.__xmlSecDoc=XMLSecDoc(encrPriKeyFilePath=encrPriKeyFilePath, 99 encrPubKeyFilePath=encrPubKeyFilePath) 111 encrPubKeyFilePath=encrPubKeyFilePath, 112 signingKeyFilePath=signingKeyFilePath, 113 certFilePathList=certFilePathList) 100 114 except Exception, e: 101 115 raise XMLMsgError("Error initialising XML security: %s" % e) … … 115 129 try: 116 130 self.decrypt(encrPriKeyPwd, encrXMLtxt) 117 131 118 132 except Exception, e: 119 133 raise XMLMsgError("Error decrypting input text: %s" % e) … … 428 442 self.__xmlSecDoc.decrypt(xmlTxt=xmlTxt, encrPriKeyPwd=encrPriKeyPwd) 429 443 self.__xmlTxt = str(self.__xmlSecDoc) 444 430 445 446 #_________________________________________________________________________ 447 def sign(self, 448 signingKeyFilePath=None, 449 signingKeyPwd=None, 450 signingCertFilePath=None): 451 """Digitally sign message""" 452 453 self.__xmlSecDoc.sign(xmlTxt=self.__xmlTxt, 454 signingKeyFilePath=signingKeyFilePath, 455 signingKeyPwd=signingKeyPwd, 456 certFilePathList=signingCertFilePath) 457 self.__xmlTxt = str(self.__xmlSecDoc) 458 459 460 #_________________________________________________________________________ 461 def isValidSig(self, *certFilePathList): 462 """Check digital signature of message""" 463 464 if certFilePathList == (): 465 certFilePathList = None 466 467 return self.__xmlSecDoc.isValidSig(xmlTxt=self.__xmlTxt, 468 certFilePathList=certFilePathList) -
TI12-security/trunk/python/NDG/XMLSecDoc.py
r751 r920 31 31 32 32 # XML security module 33 import xmlsec 34 35 36 37 class XMLSecDocMetaClass(type): 38 def __init__(cls, name, bases, dict): 39 40 # Init xmlsec library 41 if xmlsec.init() < 0: 42 raise XMLSecDocError("xmlsec initialization failed.") 43 44 45 # Check loaded library version 46 if xmlsec.checkVersion() != 1: 47 raise XMLSecDocError("xmlsec library version is not compatible.") 48 49 50 # Init crypto library 51 if xmlsec.cryptoAppInit(None) < 0: 52 raise XMLSecDocError("Crypto initialization failed.") 53 54 55 # Init xmlsec-crypto library 56 if xmlsec.cryptoInit() < 0: 57 raise XMLSecDocError("xmlsec-crypto initialization failed.") 58 33 import xmlsec 59 34 60 35 … … 67 42 def __str__(self): 68 43 return self.__msg 69 70 71 44 72 45 … … 413 386 elif isinstance(filePath, list): 414 387 self.__certFilePathList = filePath 388 389 elif isinstance(filePath, tuple): 390 self.__certFilePathList = list(filePath) 415 391 416 392 else: … … 550 526 signingKeyPwd: password for signing key file. 551 527 552 certFilePathList: file path to certificate file of Attribute 553 Authority - may also be set in __init__ 528 certFilePathList: file paths to certificate files 554 529 """ 555 530 … … 611 586 signingKeyPwd: password for signing key file. 612 587 613 certFilePathList: file path to certificate file of Attribute 614 Authority - may also be set in __init__ 588 certFilePathList: include certificate of signer 615 589 inclX509Cert: include MIME encoded content of X.509 616 590 certificate that will sign the document … … 784 758 by self.__filePath is read instead. 785 759 786 certFilePathList: Certificate used to sign the document.760 certFilePathList: Certificate used to sign the document. 787 761 """ 788 762 -
TI12-security/trunk/python/NDG/log_services_server.py
r917 r920 13 13 version 1.0 or later. 14 14 """ 15 import os 15 16 16 17 from log_services import * … … 18 19 19 20 from Log import * 21 from LogIO import * 20 22 21 23 … … 36 38 self.__srv = srv 37 39 self.__debug = debug 40 self.__caCertFilePath = os.path.expandvars(\ 41 "$NDG_DIR/conf/certs/cacert.pem") 38 42 39 43 … … 46 50 47 51 # input vals in request object 48 args = ps.Parse(debugRequestWrapper)49 req Txt = str(args._debugReq)52 reqArgs = ps.Parse(debugRequestWrapper) 53 req = DebugReq(xmlTxt=str(reqArgs._debugReq)) 50 54 51 55 # assign return values to response object 52 56 response = debugResponseWrapper() 53 57 54 try: 55 self.__srv.debug(reqTxt) 58 try: 59 if not req.isValidSig(self.__caCertFilePath): 60 response._debugResp = "Client signature is invalid" 61 62 self.__srv.debug(req['msg']) 56 63 57 64 except Exception, e: … … 70 77 71 78 # input vals in request object 72 args = ps.Parse(errorRequestWrapper)73 req Txt = str(args._errorReq)79 reqArgs = ps.Parse(errorRequestWrapper) 80 req = ErrorReq(xmlTxt=str(reqArgs._errorReq)) 74 81 75 82 # assign return values to response object … … 77 84 78 85 try: 79 self.__srv.error(reqTxt) 86 if not req.isValidSig(self.__caCertFilePath): 87 response._errorResp = "Client signature is invalid" 88 89 self.__srv.error(req['msg']) 80 90 81 91 except Exception, e: … … 94 104 95 105 # input vals in request object 96 args = ps.Parse(infoRequestWrapper)97 req Txt = str(args._infoReq)106 reqArgs = ps.Parse(infoRequestWrapper) 107 req = InfoReq(xmlTxt=str(reqArgs._infoReq)) 98 108 99 109 # assign return values to response object … … 101 111 102 112 try: 103 self.__srv.info(reqTxt) 113 if not req.isValidSig(self.__caCertFilePath): 114 response._infoResp = "Client signature is invalid" 115 116 self.__srv.info(req['msg']) 104 117 105 118 except Exception, e: … … 118 131 119 132 # input vals in request object 120 args = ps.Parse(warningRequestWrapper)121 req Txt = str(args._warningReq)133 reqArgs = ps.Parse(warningRequestWrapper) 134 req = WarningReq(xmlTxt=str(reqArgs._warningReq)) 122 135 123 136 # assign return values to response object … … 125 138 126 139 try: 127 self.__srv.warning(reqTxt) 140 if not req.isValidSig(self.__caCertFilePath): 141 response._warningResp = "Client signature is invalid" 142 143 self.__srv.warning(req['msg']) 128 144 129 145 except Exception, e:
Note: See TracChangeset
for help on using the changeset viewer.