Changeset 1856 for TI12-security
- Timestamp:
- 13/12/06 08:56:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/Tests/MyProxyClient/m2CryptoMyPxClnt.py
r1854 r1856 35 35 36 36 class MyProxyClient(object): 37 """MyProxy client interface 37 """MyProxy client interface 38 39 Based on protocol definitions in: 40 41 http://grid.ncsa.uiuc.edu/myproxy/protocol/ 38 42 39 43 @cvar __getCmd: get command string … … 48 52 PASSPHRASE=%s 49 53 LIFETIME=%d\0""" 50 54 51 55 __infoCmd="""VERSION=MYPROXYv2 52 56 COMMAND=2 … … 60 64 PASSPHRASE=PASSPHRASE 61 65 LIFETIME=0""" 66 67 __changePassphraseCmd="""VERSION=MYPROXYv2 68 COMMAND=4 69 USERNAME=%s 70 PASSPHRASE=%s 71 NEW_PHRASE=%s 72 LIFETIME=0""" 62 73 63 74 __storeCmd="""VERSION=MYPROXYv2 … … 270 281 "No client authentication cert. and private key file were given" 271 282 272 import pdb;pdb.set_trace() 283 273 284 context = Context(protocol='sslv3') 274 285 context.load_cert(ownerCertFile, … … 293 304 294 305 # send info command 295 cmd = MyProxyClient.__infoCmd % (username)306 cmd = MyProxyClient.__infoCmd % username 296 307 conn.write(cmd) 297 308 … … 306 317 307 318 return not bool(respCode), errorTxt, field 319 320 321 #_________________________________________________________________________ 322 def changePassphrase(self, 323 username, 324 passphrase, 325 newPassphrase, 326 ownerCertFile=None, 327 ownerKeyFile=None, 328 ownerPassphrase=None): 329 """change pass-phrase protecting the credentials for a given username 330 331 Exceptions: GetError, StoreCredError 332 333 @param username: username of credential 334 @param passphrase: existing pass-phrase for credential 335 @param newPassphrase: new pass-phrase to replace the existing one. 336 @param ownerCertFile: certificate used for client authentication with 337 the MyProxy server SSL connection. This ID will be set as the owner 338 of the stored credentials. Only the owner can later remove 339 credentials with myproxy-destroy or the destroy method. If not set, 340 this argument defaults to $GLOBUS_LOCATION/etc/hostcert.pem 341 @param ownerKeyFile: corresponding private key file. See explanation 342 for ownerCertFile 343 @param ownerPassphrase: passphrase for ownerKeyFile. Omit if the 344 private key is not password protected. 345 @return none 346 """ 347 globusLoc = os.environ.get('GLOBUS_LOCATION') 348 if not ownerCertFile or not ownerKeyFile: 349 if globusLoc: 350 ownerCertFile = os.path.join(globusLoc, 'etc', 'hostcert.pem') 351 ownerKeyFile = os.path.join(globusLoc, 'etc', 'hostkey.pem') 352 else: 353 raise MyProxyClientError, \ 354 "No client authentication cert. and private key file were given" 355 356 import pdb;pdb.set_trace() 357 context = Context(protocol='sslv3') 358 context.load_cert(ownerCertFile, 359 keyfile=ownerKeyFile, 360 callback=lambda *ar, **kw: ownerPassphrase) 361 362 # Disable for compatibility with myproxy server (er, globus) 363 # globus doesn't handle this case, apparently, and instead 364 # chokes in proxy delegation code 365 context.set_options(m2.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) 366 367 # connect to myproxy server 368 conn = Connection(context, sock=socket.socket()) 369 370 # Fudge to avoid checking client cert - seems to pick globus 371 # host/<hostname> one 372 conn.clientPostConnectionCheck = None 373 conn.connect((self.hostname, self.port)) 374 375 # send globus compatibility stuff 376 conn.write('0') 377 378 # send command 379 cmd = MyProxyClient.__changePassphraseCmd % (username, 380 passphrase, 381 newPassphrase) 382 conn.write(cmd) 383 384 # process server response 385 dat = conn.recv(8192) 386 387 respCode, errorTxt = self._deserializeResponse(dat) 388 if respCode: 389 raise GetError, errorTxt 308 390 309 391 … … 339 421 "No client authentication cert. and private key file were given" 340 422 341 import pdb;pdb.set_trace() 423 342 424 context = Context(protocol='sslv3') 343 425 context.load_cert(ownerCertFile, … … 361 443 conn.write('0') 362 444 363 # send storecommand364 cmd = MyProxyClient.__destroyCmd % (username)445 # send destroy command 446 cmd = MyProxyClient.__destroyCmd % username 365 447 conn.write(cmd) 366 448 … … 412 494 ownerKeyFile = keyFile 413 495 414 import pdb;pdb.set_trace() 496 415 497 context = Context(protocol='sslv3') 416 498 context.load_cert(ownerCertFile, … … 562 644 action="store_true", 563 645 help="destroy credential") 646 647 parser.add_option("-C", 648 "--change-pass-phrase", 649 dest="changePassphrase", 650 default=False, 651 action="store_true", 652 help="change pass-phrase protecting credential") 564 653 565 654 parser.add_option("-g", … … 659 748 (username, outfile) 660 749 750 except Exception,e: 751 print "Error:", e 752 sys.exit(1) 753 754 elif options.changePassphrase: 755 756 # Get MyProxy password 757 passphrase = getpass.getpass(\ 758 prompt='Enter (current) MyProxy pass phrase: ') 759 760 newPassphrase = getpass.getpass(\ 761 prompt='Enter new MyProxy pass phrase: ') 762 763 if newPassphrase != getpass.getpass(\ 764 prompt='Verifying - Enter new MyProxy pass phrase: '): 765 raise Exception, "Pass-phrases entered don't match" 766 767 768 # Retrieve proxy cert 769 try: 770 myProxy.changePassphrase(username, 771 passphrase, 772 newPassphrase, 773 options.certFile, 774 options.keyFile, 775 ownerPassphrase=open('../tmp2').read().strip()) 661 776 except Exception,e: 662 777 print "Error:", e
Note: See TracChangeset
for help on using the changeset viewer.