Show More
@@ -5,11 +5,12 b' from boards.utils import get_file_mimety' | |||
|
5 | 5 | from django.db import transaction |
|
6 | 6 | from boards.models import KeyPair, GlobalId, Signature, Post, Tag |
|
7 | 7 | |
|
8 | EXCEPTION_NODE = 'Sync node returned an error: {}' | |
|
9 | EXCEPTION_OP = 'Load the OP first' | |
|
10 | EXCEPTION_DOWNLOAD = 'File was not downloaded' | |
|
11 | EXCEPTION_HASH = 'File hash does not match attachment hash' | |
|
12 | EXCEPTION_SIGNATURE = 'Invalid model signature for {}' | |
|
8 | EXCEPTION_NODE = 'Sync node returned an error: {}.' | |
|
9 | EXCEPTION_OP = 'Load the OP first.' | |
|
10 | EXCEPTION_DOWNLOAD = 'File was not downloaded.' | |
|
11 | EXCEPTION_HASH = 'File hash does not match attachment hash.' | |
|
12 | EXCEPTION_SIGNATURE = 'Invalid model signature for {}.' | |
|
13 | EXCEPTION_AUTHOR_SIGNATURE = 'Model {} has no author signature.' | |
|
13 | 14 | ENCODING_UNICODE = 'unicode' |
|
14 | 15 | |
|
15 | 16 | TAG_MODEL = 'model' |
@@ -166,10 +167,10 b' class SyncManager:' | |||
|
166 | 167 | tag_content = tag_model.find(TAG_CONTENT) |
|
167 | 168 | |
|
168 | 169 | content_str = et.tostring(tag_content, ENCODING_UNICODE) |
|
169 | signatures = SyncManager._verify_model(content_str, tag_model) | |
|
170 | 170 | |
|
171 | 171 | tag_id = tag_content.find(TAG_ID) |
|
172 | 172 | global_id, exists = GlobalId.from_xml_element(tag_id) |
|
173 | signatures = SyncManager._verify_model(global_id, content_str, tag_model) | |
|
173 | 174 | |
|
174 | 175 | if exists: |
|
175 | 176 | print('Post with same ID already exists') |
@@ -253,7 +254,7 b' class SyncManager:' | |||
|
253 | 254 | return et.tostring(response, ENCODING_UNICODE) |
|
254 | 255 | |
|
255 | 256 | @staticmethod |
|
256 | def _verify_model(content_str, tag_model): | |
|
257 | def _verify_model(global_id, content_str, tag_model): | |
|
257 | 258 | """ |
|
258 | 259 | Verifies all signatures for a single model. |
|
259 | 260 | """ |
@@ -261,11 +262,16 b' class SyncManager:' | |||
|
261 | 262 | signatures = [] |
|
262 | 263 | |
|
263 | 264 | tag_signatures = tag_model.find(TAG_SIGNATURES) |
|
265 | has_author_signature = False | |
|
264 | 266 | for tag_signature in tag_signatures: |
|
265 | 267 | signature_type = tag_signature.get(ATTR_TYPE) |
|
266 | 268 | signature_value = tag_signature.get(ATTR_VALUE) |
|
267 | 269 | signature_key = tag_signature.get(ATTR_KEY) |
|
268 | 270 | |
|
271 | if global_id.key_type == signature_type and\ | |
|
272 | global_id.key == signature_key: | |
|
273 | has_author_signature = True | |
|
274 | ||
|
269 | 275 | signature = Signature(key_type=signature_type, |
|
270 | 276 | key=signature_key, |
|
271 | 277 | signature=signature_value) |
@@ -274,6 +280,8 b' class SyncManager:' | |||
|
274 | 280 | raise SyncException(EXCEPTION_SIGNATURE.format(content_str)) |
|
275 | 281 | |
|
276 | 282 | signatures.append(signature) |
|
283 | if not has_author_signature: | |
|
284 | raise SyncException(EXCEPTION_AUTHOR_SIGNATURE.format(content_str)) | |
|
277 | 285 | |
|
278 | 286 | return signatures |
|
279 | 287 |
General Comments 0
You need to be logged in to leave comments.
Login now