|
34 | 34 | from saml2.s_utils import sid
|
35 | 35 | from saml2.s_utils import UnravelError
|
36 | 36 | from saml2.s_utils import error_status_factory
|
37 |
| -from saml2.s_utils import rndstr |
| 37 | +from saml2.s_utils import rndbytes |
38 | 38 | from saml2.s_utils import success_status_factory
|
39 | 39 | from saml2.s_utils import decode_base64_and_inflate
|
40 | 40 | from saml2.s_utils import UnsupportedBinding
|
|
73 | 73 |
|
74 | 74 | __author__ = 'rolandh'
|
75 | 75 |
|
76 |
| -ARTIFACT_TYPECODE = '\x00\x04' |
| 76 | +ARTIFACT_TYPECODE = b'\x00\x04' |
77 | 77 |
|
78 | 78 | SERVICE2MESSAGE = {
|
79 | 79 | "single_sign_on_service": AuthnRequest,
|
@@ -103,11 +103,17 @@ def create_artifact(entity_id, message_handle, endpoint_index=0):
|
103 | 103 | :param endpoint_index:
|
104 | 104 | :return:
|
105 | 105 | """
|
| 106 | + if not isinstance(entity_id, six.binary_type): |
| 107 | + entity_id = entity_id.encode('utf-8') |
106 | 108 | sourceid = sha1(entity_id)
|
107 | 109 |
|
108 |
| - ter = "%s%.2x%s%s" % (ARTIFACT_TYPECODE, endpoint_index, |
109 |
| - sourceid.digest(), message_handle) |
110 |
| - return base64.b64encode(ter) |
| 110 | + if not isinstance(message_handle, six.binary_type): |
| 111 | + message_handle = message_handle.encode('utf-8') |
| 112 | + ter = b"".join((ARTIFACT_TYPECODE, |
| 113 | + ("%.2x" % endpoint_index).encode('ascii'), |
| 114 | + sourceid.digest(), |
| 115 | + message_handle)) |
| 116 | + return base64.b64encode(ter).decode('ascii') |
111 | 117 |
|
112 | 118 |
|
113 | 119 | class Entity(HTTPBase):
|
@@ -1115,8 +1121,8 @@ def use_artifact(self, message, endpoint_index=0):
|
1115 | 1121 | :param endpoint_index:
|
1116 | 1122 | :return:
|
1117 | 1123 | """
|
1118 |
| - message_handle = sha1("%s" % message) |
1119 |
| - message_handle.update(rndstr()) |
| 1124 | + message_handle = sha1(str(message).encode('utf-8')) |
| 1125 | + message_handle.update(rndbytes()) |
1120 | 1126 | mhd = message_handle.digest()
|
1121 | 1127 | saml_art = create_artifact(self.config.entityid, mhd, endpoint_index)
|
1122 | 1128 | self.artifact[saml_art] = message
|
|
0 commit comments