@@ -115,9 +115,7 @@ def unpack_redirect(self):
115
115
116
116
def unpack_post (self ):
117
117
post_data = get_post (self .environ )
118
- _dict = parse_qs (
119
- post_data if isinstance (post_data , str ) else post_data .decode ("utf-8" )
120
- )
118
+ _dict = parse_qs (post_data if isinstance (post_data , str ) else post_data .decode ("utf-8" ))
121
119
logger .debug ("unpack_post:: %s" , _dict )
122
120
try :
123
121
return dict ([(k , v [0 ]) for k , v in _dict .items ()])
@@ -161,9 +159,7 @@ def operation(self, saml_msg, binding):
161
159
kwargs = {}
162
160
163
161
try :
164
- kwargs ["encrypt_cert" ] = encrypt_cert_from_item (
165
- saml_msg ["req_info" ].message
166
- )
162
+ kwargs ["encrypt_cert" ] = encrypt_cert_from_item (saml_msg ["req_info" ].message )
167
163
except KeyError :
168
164
pass
169
165
@@ -356,10 +352,7 @@ def do(self, query, binding_in, relay_state="", encrypt_cert=None, **kwargs):
356
352
resp_args ["authn" ] = metod
357
353
358
354
_resp = IDP .create_authn_response (
359
- identity ,
360
- userid = self .user ,
361
- encrypt_cert_assertion = encrypt_cert ,
362
- ** resp_args
355
+ identity , userid = self .user , encrypt_cert_assertion = encrypt_cert , ** resp_args
363
356
)
364
357
except Exception as excp :
365
358
logging .error (exception_trace (excp ))
@@ -368,21 +361,12 @@ def do(self, query, binding_in, relay_state="", encrypt_cert=None, **kwargs):
368
361
369
362
logger .info ("AuthNResponse: %s" , _resp )
370
363
if self .op_type == "ecp" :
371
- kwargs = {
372
- "soap_headers" : [
373
- ecp .Response (assertion_consumer_service_url = self .destination )
374
- ]
375
- }
364
+ kwargs = {"soap_headers" : [ecp .Response (assertion_consumer_service_url = self .destination )]}
376
365
else :
377
366
kwargs = {}
378
367
379
368
http_args = IDP .apply_binding (
380
- self .binding_out ,
381
- "%s" % _resp ,
382
- self .destination ,
383
- relay_state ,
384
- response = True ,
385
- ** kwargs
369
+ self .binding_out , "%s" % _resp , self .destination , relay_state , response = True , ** kwargs
386
370
)
387
371
388
372
logger .debug ("HTTPargs: %s" , http_args )
@@ -409,9 +393,7 @@ def redirect(self):
409
393
del IDP .ticket [_key ]
410
394
except KeyError :
411
395
try :
412
- self .req_info = IDP .parse_authn_request (
413
- saml_msg ["SAMLRequest" ], BINDING_HTTP_REDIRECT
414
- )
396
+ self .req_info = IDP .parse_authn_request (saml_msg ["SAMLRequest" ], BINDING_HTTP_REDIRECT )
415
397
except KeyError :
416
398
resp = BadRequest ("Message signature verification failure" )
417
399
return resp (self .environ , self .start_response )
@@ -462,9 +444,7 @@ def post(self):
462
444
self .req_info = saml_msg ["req_info" ]
463
445
del IDP .ticket [_key ]
464
446
except KeyError :
465
- self .req_info = IDP .parse_authn_request (
466
- saml_msg ["SAMLRequest" ], BINDING_HTTP_POST
467
- )
447
+ self .req_info = IDP .parse_authn_request (saml_msg ["SAMLRequest" ], BINDING_HTTP_POST )
468
448
_req = self .req_info .message
469
449
if self .user :
470
450
if _req .force_authn is not None and _req .force_authn .lower () == "true" :
@@ -505,9 +485,7 @@ def ecp(self):
505
485
if is_equal (PASSWD [user ], passwd ):
506
486
resp = Unauthorized ()
507
487
self .user = user
508
- self .environ ["idp.authn" ] = AUTHN_BROKER .get_authn_by_accr (
509
- PASSWORD
510
- )
488
+ self .environ ["idp.authn" ] = AUTHN_BROKER .get_authn_by_accr (PASSWORD )
511
489
except ValueError :
512
490
resp = Unauthorized ()
513
491
else :
@@ -530,9 +508,7 @@ def ecp(self):
530
508
# -----------------------------------------------------------------------------
531
509
532
510
533
- def do_authentication (
534
- environ , start_response , authn_context , key , redirect_uri , headers = None
535
- ):
511
+ def do_authentication (environ , start_response , authn_context , key , redirect_uri , headers = None ):
536
512
"""
537
513
Display the login form
538
514
"""
@@ -560,9 +536,7 @@ def do_authentication(
560
536
}
561
537
562
538
563
- def username_password_authn (
564
- environ , start_response , reference , key , redirect_uri , headers = None
565
- ):
539
+ def username_password_authn (environ , start_response , reference , key , redirect_uri , headers = None ):
566
540
"""
567
541
Display the login form
568
542
"""
@@ -681,15 +655,11 @@ def do(self, request, binding, relay_state="", encrypt_cert=None, **kwargs):
681
655
destination = ""
682
656
response = False
683
657
else :
684
- binding , destination = IDP .pick_binding (
685
- "single_logout_service" , [binding ], "spsso" , req_info
686
- )
658
+ binding , destination = IDP .pick_binding ("single_logout_service" , [binding ], "spsso" , req_info )
687
659
response = True
688
660
689
661
try :
690
- hinfo = IDP .apply_binding (
691
- binding , "%s" % resp , destination , relay_state , response = response
692
- )
662
+ hinfo = IDP .apply_binding (binding , "%s" % resp , destination , relay_state , response = response )
693
663
except Exception as exc :
694
664
logger .error ("ServiceError: %s" , exc )
695
665
resp = ServiceError ("%s" % exc )
@@ -735,9 +705,7 @@ def do(self, query, binding, relay_state="", encrypt_cert=None):
735
705
_resp = IDP .create_manage_name_id_response (request )
736
706
737
707
# It's using SOAP binding
738
- hinfo = IDP .apply_binding (
739
- BINDING_SOAP , "%s" % _resp , "" , relay_state , response = True
740
- )
708
+ hinfo = IDP .apply_binding (BINDING_SOAP , "%s" % _resp , "" , relay_state , response = True )
741
709
742
710
resp = Response (hinfo ["data" ], headers = hinfo ["headers" ])
743
711
return resp (self .environ , self .start_response )
@@ -803,9 +771,7 @@ def do(self, request, binding, relay_state="", encrypt_cert=None):
803
771
_req = IDP .parse_authn_query (request , binding )
804
772
_query = _req .message
805
773
806
- msg = IDP .create_authn_query_response (
807
- _query .subject , _query .requested_authn_context , _query .session_index
808
- )
774
+ msg = IDP .create_authn_query_response (_query .subject , _query .requested_authn_context , _query .session_index )
809
775
810
776
logger .debug ("response: %s" , msg )
811
777
hinfo = IDP .apply_binding (BINDING_SOAP , "%s" % msg , "" , "" , response = True )
@@ -858,9 +824,7 @@ def do(self, query, binding, relay_state="", encrypt_cert=None):
858
824
request = req .message
859
825
# Do the necessary stuff
860
826
try :
861
- name_id = IDP .ident .handle_name_id_mapping_request (
862
- request .name_id , request .name_id_policy
863
- )
827
+ name_id = IDP .ident .handle_name_id_mapping_request (request .name_id , request .name_id_policy )
864
828
except Unknown :
865
829
resp = BadRequest ("Unknown entity" )
866
830
return resp (self .environ , self .start_response )
@@ -1095,33 +1059,25 @@ def application(environ, start_response):
1095
1059
1096
1060
if __name__ == "__main__" :
1097
1061
parser = argparse .ArgumentParser ()
1098
- parser .add_argument (
1099
- "-p" , dest = "path" , help = "Path to configuration file." , default = "./idp_conf.py"
1100
- )
1062
+ parser .add_argument ("-p" , dest = "path" , help = "Path to configuration file." , default = "./idp_conf.py" )
1101
1063
parser .add_argument (
1102
1064
"-v" ,
1103
1065
dest = "valid" ,
1104
1066
help = "How long, in days, the metadata is valid from " "the time of creation" ,
1105
1067
)
1106
1068
parser .add_argument ("-c" , dest = "cert" , help = "certificate" )
1107
1069
parser .add_argument ("-i" , dest = "id" , help = "The ID of the entities descriptor" )
1108
- parser .add_argument (
1109
- "-k" , dest = "keyfile" , help = "A file with a key to sign the metadata with"
1110
- )
1070
+ parser .add_argument ("-k" , dest = "keyfile" , help = "A file with a key to sign the metadata with" )
1111
1071
parser .add_argument ("-n" , dest = "name" )
1112
- parser .add_argument (
1113
- "-s" , dest = "sign" , action = "store_true" , help = "sign the metadata"
1114
- )
1072
+ parser .add_argument ("-s" , dest = "sign" , action = "store_true" , help = "sign the metadata" )
1115
1073
parser .add_argument ("-m" , dest = "mako_root" , default = "./" )
1116
1074
parser .add_argument (dest = "config" )
1117
1075
args = parser .parse_args ()
1118
1076
1119
1077
CONFIG = importlib .import_module (args .config )
1120
1078
1121
1079
AUTHN_BROKER = AuthnBroker ()
1122
- AUTHN_BROKER .add (
1123
- authn_context_class_ref (PASSWORD ), username_password_authn , 10 , CONFIG .BASE
1124
- )
1080
+ AUTHN_BROKER .add (authn_context_class_ref (PASSWORD ), username_password_authn , 10 , CONFIG .BASE )
1125
1081
AUTHN_BROKER .add (authn_context_class_ref (UNSPECIFIED ), "" , 0 , CONFIG .BASE )
1126
1082
1127
1083
IDP = server .Server (args .config , cache = Cache ())
@@ -1157,9 +1113,7 @@ def application(environ, start_response):
1157
1113
https = "using HTTPS"
1158
1114
# SRV.ssl_adapter = ssl_pyopenssl.pyOpenSSLAdapter(
1159
1115
# config.SERVER_CERT, config.SERVER_KEY, config.CERT_CHAIN)
1160
- SRV .ssl_adapter = BuiltinSSLAdapter (
1161
- CONFIG .SERVER_CERT , CONFIG .SERVER_KEY , CONFIG .CERT_CHAIN
1162
- )
1116
+ SRV .ssl_adapter = BuiltinSSLAdapter (CONFIG .SERVER_CERT , CONFIG .SERVER_KEY , CONFIG .CERT_CHAIN )
1163
1117
1164
1118
logger .info ("Server starting" )
1165
1119
print ("IDP listening on %s:%s%s" % (HOST , PORT , _https ))
0 commit comments