|
1 | 1 | #!/usr/bin/env python
|
2 |
| -import logging |
3 |
| -import random |
4 | 2 |
|
5 |
| -import time |
6 | 3 | import base64
|
7 |
| -import six |
8 |
| -import sys |
| 4 | +import hashlib |
9 | 5 | import hmac
|
| 6 | +import logging |
| 7 | +import random |
10 | 8 | import string
|
11 |
| - |
12 |
| -# from python 2.5 |
13 |
| -import imp |
| 9 | +import sys |
| 10 | +import time |
14 | 11 | import traceback
|
| 12 | +import zlib |
15 | 13 |
|
16 |
| -if sys.version_info >= (2, 5): |
17 |
| - import hashlib |
18 |
| -else: # before python 2.5 |
19 |
| - import sha |
| 14 | +import six |
20 | 15 |
|
21 | 16 | from saml2 import saml
|
22 | 17 | from saml2 import samlp
|
23 | 18 | from saml2 import VERSION
|
24 | 19 | from saml2.time_util import instant
|
25 | 20 |
|
26 |
| -try: |
27 |
| - from hashlib import md5 |
28 |
| -except ImportError: |
29 |
| - from md5 import md5 |
30 |
| -import zlib |
31 | 21 |
|
32 | 22 | logger = logging.getLogger(__name__)
|
33 | 23 |
|
@@ -407,67 +397,6 @@ def verify_signature(secret, parts):
|
407 | 397 | return False
|
408 | 398 |
|
409 | 399 |
|
410 |
| -FTICKS_FORMAT = "F-TICKS/SWAMID/2.0%s#" |
411 |
| - |
412 |
| - |
413 |
| -def fticks_log(sp, logf, idp_entity_id, user_id, secret, assertion): |
414 |
| - """ |
415 |
| - 'F-TICKS/' federationIdentifier '/' version *('#' attribute '=' value) '#' |
416 |
| - Allowed attributes: |
417 |
| - TS the login time stamp |
418 |
| - RP the relying party entityID |
419 |
| - AP the asserting party entityID (typcially the IdP) |
420 |
| - PN a sha256-hash of the local principal name and a unique key |
421 |
| - AM the authentication method URN |
422 |
| -
|
423 |
| - :param sp: Client instance |
424 |
| - :param logf: The log function to use |
425 |
| - :param idp_entity_id: IdP entity ID |
426 |
| - :param user_id: The user identifier |
427 |
| - :param secret: A salt to make the hash more secure |
428 |
| - :param assertion: A SAML Assertion instance gotten from the IdP |
429 |
| - """ |
430 |
| - csum = hmac.new(secret, digestmod=hashlib.sha1) |
431 |
| - csum.update(user_id) |
432 |
| - ac = assertion.AuthnStatement[0].AuthnContext[0] |
433 |
| - |
434 |
| - info = { |
435 |
| - "TS": time.time(), |
436 |
| - "RP": sp.entity_id, |
437 |
| - "AP": idp_entity_id, |
438 |
| - "PN": csum.hexdigest(), |
439 |
| - "AM": ac.AuthnContextClassRef.text |
440 |
| - } |
441 |
| - logf.info(FTICKS_FORMAT % "#".join(["%s=%s" % (a, v) for a, v in info])) |
442 |
| - |
443 |
| - |
444 |
| -def dynamic_importer(name, class_name=None): |
445 |
| - """ |
446 |
| - Dynamically imports modules / classes |
447 |
| - """ |
448 |
| - try: |
449 |
| - fp, pathname, description = imp.find_module(name) |
450 |
| - except ImportError: |
451 |
| - print("unable to locate module: " + name) |
452 |
| - return None, None |
453 |
| - |
454 |
| - try: |
455 |
| - package = imp.load_module(name, fp, pathname, description) |
456 |
| - except Exception: |
457 |
| - raise |
458 |
| - |
459 |
| - if class_name: |
460 |
| - try: |
461 |
| - _class = imp.load_module("%s.%s" % (name, class_name), fp, |
462 |
| - pathname, description) |
463 |
| - except Exception: |
464 |
| - raise |
465 |
| - |
466 |
| - return package, _class |
467 |
| - else: |
468 |
| - return package, None |
469 |
| - |
470 |
| - |
471 | 400 | def exception_trace(exc):
|
472 | 401 | message = traceback.format_exception(*sys.exc_info())
|
473 | 402 |
|
|
0 commit comments