1010"""
1111
1212import urllib2
13+ import ssl
1314
1415from copy import deepcopy
1516from defusedxml .lxml import fromstring
@@ -24,7 +25,7 @@ class OneLogin_Saml2_IdPMetadataParser(object):
2425 """
2526
2627 @staticmethod
27- def get_metadata (url ):
28+ def get_metadata (url , validate_cert = True ):
2829 """
2930 Gets the metadata XML from the provided URL
3031
@@ -35,7 +36,13 @@ def get_metadata(url):
3536 :rtype: string
3637 """
3738 valid = False
38- response = urllib2 .urlopen (url )
39+ if validate_cert :
40+ response = urllib2 .urlopen (url )
41+ else :
42+ ctx = ssl .create_default_context ()
43+ ctx .check_hostname = False
44+ ctx .verify_mode = ssl .CERT_NONE
45+ response = urllib2 .urlopen (url , context = ctx )
3946 xml = response .read ()
4047
4148 if xml :
@@ -53,7 +60,7 @@ def get_metadata(url):
5360 return xml
5461
5562 @staticmethod
56- def parse_remote (url , ** kwargs ):
63+ def parse_remote (url , validate_cert = True , ** kwargs ):
5764 """
5865 Gets the metadata XML from the provided URL and parse it, returning a dict with extracted data
5966
@@ -63,7 +70,7 @@ def parse_remote(url, **kwargs):
6370 :returns: settings dict with extracted data
6471 :rtype: dict
6572 """
66- idp_metadata = OneLogin_Saml2_IdPMetadataParser .get_metadata (url )
73+ idp_metadata = OneLogin_Saml2_IdPMetadataParser .get_metadata (url , validate_cert )
6774 return OneLogin_Saml2_IdPMetadataParser .parse (idp_metadata , ** kwargs )
6875
6976 @staticmethod
0 commit comments