##// END OF EJS Templates
Don't stringify content tag twice
neko259 -
r1537:ae763fd6 decentral
parent child Browse files
Show More
@@ -149,7 +149,8 b' class SyncManager:'
149 149 for tag_model in tag_models:
150 150 tag_content = tag_model.find(TAG_CONTENT)
151 151
152 signatures = SyncManager._verify_model(tag_content, tag_model)
152 content_str = et.tostring(tag_content, ENCODING_UNICODE)
153 signatures = SyncManager._verify_model(content_str, tag_model)
153 154
154 155 tag_id = tag_content.find(TAG_ID)
155 156 global_id, exists = GlobalId.from_xml_element(tag_id)
@@ -157,8 +158,7 b' class SyncManager:'
157 158 if exists:
158 159 print('Post with same ID already exists')
159 160 else:
160 global_id.content = et.tostring(tag_content,
161 ENCODING_UNICODE)
161 global_id.content = content_str
162 162 global_id.save()
163 163 for signature in signatures:
164 164 signature.global_id = global_id
@@ -229,7 +229,7 b' class SyncManager:'
229 229 return et.tostring(response, ENCODING_UNICODE)
230 230
231 231 @staticmethod
232 def _verify_model(tag_content, tag_model):
232 def _verify_model(content_str, tag_model):
233 233 """
234 234 Verifies all signatures for a single model.
235 235 """
@@ -246,11 +246,8 b' class SyncManager:'
246 246 key=signature_key,
247 247 signature=signature_value)
248 248
249 content = et.tostring(tag_content, ENCODING_UNICODE)
250
251 if not KeyPair.objects.verify(
252 signature, content):
253 raise SyncException('Invalid model signature for {}'.format(content))
249 if not KeyPair.objects.verify(signature, content_str):
250 raise SyncException('Invalid model signature for {}'.format(content_str))
254 251
255 252 signatures.append(signature)
256 253
General Comments 0
You need to be logged in to leave comments. Login now