Skip to content

Commit 5a1add6

Browse files
author
Hans Hörberg
committed
Merge remote-tracking branch 'upstream/master'
2 parents aefd9b3 + 52028d3 commit 5a1add6

30 files changed

+136
-58
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def run_tests(self):
4242
'python-memcached >= 1.51',
4343
'pytest',
4444
'mako',
45+
'webob',
4546
#'pytest-coverage',
4647
]
4748

src/idp_test/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import types
77
import argparse
88
import sys
9+
import six
910

1011
import logging
1112
import imp
@@ -356,7 +357,7 @@ def list_operations(self):
356357
item = {"id": key, "name": val["name"]}
357358
try:
358359
_desc = val["descr"]
359-
if isinstance(_desc, basestring):
360+
if isinstance(_desc, six.string_types):
360361
item["descr"] = _desc
361362
else:
362363
item["descr"] = "\n".join(_desc)
@@ -377,7 +378,7 @@ def list_operations(self):
377378
item = {"id": key, "name": val["name"]}
378379
try:
379380
_desc = val["descr"]
380-
if isinstance(_desc, basestring):
381+
if isinstance(_desc, six.string_types):
381382
item["descr"] = _desc
382383
else:
383384
item["descr"] = "\n".join(_desc)

src/idp_test/interaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
import six
56

67
from urlparse import urlparse
78
from bs4 import BeautifulSoup
@@ -34,7 +35,8 @@ def pick_interaction(interactions, _base="", content="", req=None):
3435
_match += 1
3536
else:
3637
_c = _bs.title.contents
37-
if isinstance(_c, list) and not isinstance(_c, basestring):
38+
if isinstance(_c, list) and not isinstance(
39+
_c, six.string_types):
3840
for _line in _c:
3941
if val in _line:
4042
_match += 1
@@ -165,7 +167,7 @@ def pick_form(response, url=None, **kwargs):
165167
_default = _ava["value"]
166168
try:
167169
orig_val = form[prop]
168-
if isinstance(orig_val, basestring):
170+
if isinstance(orig_val, six.string_types):
169171
if orig_val == _default:
170172
_form = form
171173
elif _default in orig_val:

src/idp_test/package/authn_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def pre_processing(self, message, args):
3030
return message
3131

3232
OPERATIONS = {
33-
'authn_unkown-issuer': {
33+
'authn_unknown-issuer': {
3434
"name": 'AuthnRequest with unknown issuer',
3535
"descr": 'AuthnRequest with unknown issuer',
3636
"sequence": [AuthnRequest_UnknownIssuer],
3737
"depends": ['authn'],
3838
"tests": {"pre": [CheckSaml2IntMetaData],
3939
"post": [CheckSaml2IntAttributes]}
4040
},
41-
'authn_unkown-extension': {
41+
'authn_unknown-extension': {
4242
"name": 'AuthnRequest with unknown extension',
4343
"descr": 'AuthnRequest with unknown extension',
4444
"sequence": [AuthnRequest_UnknownExtension],
4545
"depends": ['authn'],
4646
"tests": {"pre": [CheckSaml2IntMetaData],
4747
"post": [CheckSaml2IntAttributes]}
4848
},
49-
}
49+
}

src/saml2/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ def to_string(self, nspair=None):
675675
return ElementTree.tostring(self._to_element_tree(), encoding="UTF-8")
676676

677677
def __str__(self):
678-
return self.to_string()
678+
# Yes this is confusing. http://bugs.python.org/issue10942
679+
x = self.to_string()
680+
if not isinstance(x, six.string_types):
681+
x = x.decode('utf-8')
682+
return x
679683

680684
def keyswv(self):
681685
""" Return the keys of attributes or children that has values

src/saml2/assertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
from saml2.saml import NAME_FORMAT_URI
88
import six
9-
import xmlenc
9+
from saml2 import xmlenc
1010

1111
from saml2 import saml
1212

src/saml2/cert.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import dateutil.parser
66
import pytz
7+
import six
78
from OpenSSL import crypto
89
from os.path import join
910
from os import remove
@@ -154,10 +155,13 @@ def create_certificate(self, cert_info, request=False, valid_from=0,
154155
tmp_cert = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
155156
tmp_key = None
156157
if cipher_passphrase is not None:
158+
passphrase = cipher_passphrase["passphrase"]
159+
if isinstance(cipher_passphrase["passphrase"],
160+
six.string_types):
161+
passphrase = passphrase.encode('utf-8')
157162
tmp_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, k,
158163
cipher_passphrase["cipher"],
159-
cipher_passphrase[
160-
"passphrase"])
164+
passphrase)
161165
else:
162166
tmp_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
163167
if write_to_file:
@@ -190,7 +194,7 @@ def write_str_to_file(self, file, str_data):
190194
f.close()
191195

192196
def read_str_from_file(self, file, type="pem"):
193-
f = open(file)
197+
f = open(file, 'rt')
194198
str_data = f.read()
195199
f.close()
196200

@@ -257,7 +261,10 @@ def create_cert_signed_certificate(self, sign_cert_str, sign_key_str,
257261
cert.set_pubkey(req_cert.get_pubkey())
258262
cert.sign(ca_key, hash_alg)
259263

260-
return crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
264+
cert_dump = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
265+
if isinstance(cert_dump, six.string_types):
266+
return cert_dump
267+
return cert_dump.decode('utf-8')
261268

262269
def verify_chain(self, cert_chain_str_list, cert_str):
263270
"""
@@ -327,6 +334,8 @@ def verify(self, signing_cert_str, cert_str):
327334
"signed certificate.")
328335

329336
cert_algorithm = cert.get_signature_algorithm()
337+
if six.PY3:
338+
cert_algorithm = cert_algorithm.decode('ascii')
330339

331340
cert_asn1 = crypto.dump_certificate(crypto.FILETYPE_ASN1, cert)
332341

@@ -342,7 +351,9 @@ def verify(self, signing_cert_str, cert_str):
342351

343352
signature_payload = cert_signature_decoded.payload
344353

345-
if signature_payload[0] != '\x00':
354+
sig_pay0 = signature_payload[0]
355+
if ((isinstance(sig_pay0, int) and sig_pay0 != 0) or
356+
(isinstance(sig_pay0, str) and sig_pay0 != '\x00')):
346357
return (False,
347358
"The certificate should not contain any unused bits.")
348359

@@ -355,4 +366,4 @@ def verify(self, signing_cert_str, cert_str):
355366
except crypto.Error as e:
356367
return False, "Certificate is incorrectly signed."
357368
except Exception as e:
358-
return False, "Certificate is not valid for an unknown reason."
369+
return False, "Certificate is not valid for an unknown reason. %s" % str(e)

src/saml2/client_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
to conclude its tasks.
77
"""
88
import threading
9-
from urllib import urlencode
10-
from urlparse import urlparse
9+
from six.moves.urllib.parse import urlencode
10+
from six.moves.urllib.parse import urlparse
1111
import six
1212

1313
from saml2.entity import Entity
@@ -25,7 +25,7 @@
2525
import time
2626
from saml2.soap import make_soap_enveloped_saml_thingy
2727

28-
from urlparse import parse_qs
28+
from six.moves.urllib.parse import parse_qs
2929

3030
from saml2.s_utils import signature, UnravelError, exception_trace
3131
from saml2.s_utils import do_attributes

src/saml2/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import logging
1010
import logging.handlers
11+
import six
1112

1213
from importlib import import_module
1314

@@ -300,7 +301,7 @@ def load_complex(self, cnf, typ="", metadata_construction=False):
300301

301302
def unicode_convert(self, item):
302303
try:
303-
return unicode(item, "utf-8")
304+
return six.text_type(item, "utf-8")
304305
except TypeError:
305306
_uc = self.unicode_convert
306307
if isinstance(item, dict):

src/saml2/entity.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from hashlib import sha1
66
from Crypto.PublicKey import RSA
77
import requests
8+
import six
89
from saml2.metadata import ENDPOINTS
910
from saml2.profile import paos, ecp
1011
from saml2.soap import parse_soap_enveloped_saml_artifact_resolve
@@ -157,7 +158,7 @@ def __init__(self, entity_type, config=None, config_file="",
157158
self.sec = security_context(self.config)
158159

159160
if virtual_organization:
160-
if isinstance(virtual_organization, basestring):
161+
if isinstance(virtual_organization, six.string_types):
161162
self.vorg = self.config.vorg[virtual_organization]
162163
elif isinstance(virtual_organization, VirtualOrg):
163164
self.vorg = virtual_organization
@@ -282,7 +283,7 @@ def pick_binding(self, service, bindings=None, descr_type="", request=None,
282283
#logger.error("Bindings: %s" % bindings)
283284
#logger.error("Entities: %s" % self.metadata)
284285

285-
raise SAMLError("Unkown entity or unsupported bindings")
286+
raise SAMLError("Unknown entity or unsupported bindings")
286287

287288
def message_args(self, message_id=0):
288289
if not message_id:

0 commit comments

Comments
 (0)