From 4f8588a1cd4da31a48d6d78ec69a6ff6215bbec9 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Fri, 6 Sep 2019 11:33:38 -0400 Subject: [PATCH] formatting & prevents comment from being altered --- src/database/writes.py | 20 ++++++++++++-------- src/server/misc.py | 9 ++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/database/writes.py b/src/database/writes.py index 701bb0b..82b57fe 100644 --- a/src/database/writes.py +++ b/src/database/writes.py @@ -3,16 +3,15 @@ import sqlite3 from asyncio import coroutine -from src.database.queries import hide_comments_by_id from src.database.queries import delete_comment_by_id -from src.database.queries import get_comment_or_none -from src.database.queries import insert_comment -from src.database.queries import insert_channel from src.database.queries import get_claim_ids_from_comment_ids -from src.server.misc import validate_signature_from_claim +from src.database.queries import get_comment_or_none +from src.database.queries import hide_comments_by_id +from src.database.queries import insert_channel +from src.database.queries import insert_comment from src.server.misc import channel_matches_pattern_or_error from src.server.misc import get_claim_from_id - +from src.server.misc import validate_signature_from_claim logger = logging.getLogger(__name__) @@ -22,8 +21,13 @@ def create_comment_or_error(conn, comment, claim_id, channel_id=None, channel_na if channel_id or channel_name or signature or signing_ts: insert_channel_or_error(conn, channel_name, channel_id) comment_id = insert_comment( - conn=conn, comment=comment, claim_id=claim_id, channel_id=channel_id, - signature=signature, parent_id=parent_id, signing_ts=signing_ts + conn=conn, + comment=comment, + claim_id=claim_id, + channel_id=channel_id, + signature=signature, + parent_id=parent_id, + signing_ts=signing_ts ) return get_comment_or_none(conn, comment_id) diff --git a/src/server/misc.py b/src/server/misc.py index 0e1e0c6..897a54b 100644 --- a/src/server/misc.py +++ b/src/server/misc.py @@ -1,19 +1,18 @@ import binascii +import hashlib import logging import re from json import JSONDecodeError -import hashlib import aiohttp - import ecdsa from aiohttp import ClientConnectorError +from cryptography.exceptions import InvalidSignature from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.serialization import load_der_public_key from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.asymmetric.utils import Prehashed -from cryptography.exceptions import InvalidSignature +from cryptography.hazmat.primitives.serialization import load_der_public_key logger = logging.getLogger(__name__) @@ -130,7 +129,7 @@ def validate_signature_from_claim(claim, signature, signing_ts, data: str): def clean_input_params(kwargs: dict): for k, v in kwargs.items(): - if type(v) is str: + if type(v) is str and k is not 'comment': kwargs[k] = v.strip() if k in ID_LIST: kwargs[k] = v.lower()