1414except ImportError :
1515 import urllib2
1616
17+ import ssl
18+
1719from onelogin .saml2 .constants import OneLogin_Saml2_Constants
1820from onelogin .saml2 .xml_utils import OneLogin_Saml2_XML
1921from onelogin .saml2 .utils import OneLogin_Saml2_Utils
@@ -25,7 +27,7 @@ class OneLogin_Saml2_IdPMetadataParser(object):
2527 """
2628
2729 @staticmethod
28- def get_metadata (url ):
30+ def get_metadata (url , validate_cert = True ):
2931 """
3032 Gets the metadata XML from the provided URL
3133 :param url: Url where the XML of the Identity Provider Metadata is published.
@@ -34,7 +36,14 @@ def get_metadata(url):
3436 :rtype: string
3537 """
3638 valid = False
37- response = urllib2 .urlopen (url )
39+
40+ if validate_cert :
41+ response = urllib2 .urlopen (url )
42+ else :
43+ ctx = ssl .create_default_context ()
44+ ctx .check_hostname = False
45+ ctx .verify_mode = ssl .CERT_NONE
46+ response = urllib2 .urlopen (url , context = ctx )
3847 xml = response .read ()
3948
4049 if xml :
@@ -52,15 +61,15 @@ def get_metadata(url):
5261 return xml
5362
5463 @staticmethod
55- def parse_remote (url , ** kwargs ):
64+ def parse_remote (url , validate_cert = True , ** kwargs ):
5665 """
5766 Gets the metadata XML from the provided URL and parse it, returning a dict with extracted data
5867 :param url: Url where the XML of the Identity Provider Metadata is published.
5968 :type url: string
6069 :returns: settings dict with extracted data
6170 :rtype: dict
6271 """
63- idp_metadata = OneLogin_Saml2_IdPMetadataParser .get_metadata (url )
72+ idp_metadata = OneLogin_Saml2_IdPMetadataParser .get_metadata (url , validate_cert )
6473 return OneLogin_Saml2_IdPMetadataParser .parse (idp_metadata , ** kwargs )
6574
6675 @staticmethod
0 commit comments