Skip to content

Commit 5e17c19

Browse files
committed
Be able to relax SSL Certificate verification when retrieving idp metadata
1 parent 5c1d869 commit 5e17c19

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/onelogin/saml2/idp_metadata_parser.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111

1212
import urllib2
13+
import ssl
1314

1415
from copy import deepcopy
1516
from 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

tests/src/OneLogin/saml2_tests/signed_response_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def testResponseSignedAssertionNot(self):
4444
response = OneLogin_Saml2_Response(settings, b64encode(message))
4545

4646
self.assertEquals('someone@example.org', response.get_nameid())
47+
from onelogin.saml2.utils import OneLogin_Saml2_Utils
48+
assertion_nodes = OneLogin_Saml2_Utils.query(response.document, '//saml:Assertion')
49+
self.assertEquals(len(assertion_nodes), 1)
4750

4851
def testResponseAndAssertionSigned(self):
4952
"""

0 commit comments

Comments
 (0)