@@ -128,7 +128,8 @@ def channel_messages(db:SQLite, id, channel_id):
128128@validate_request_data ({"content" : {}, "timestamp" : {}, "signature" : {}})
129129def sending_messages (db :SQLite , id , channel_id ):
130130 files = request .files .getlist ("files" )
131- msg = request .form ["content" ].replace ("\r \n " , "\n " ).replace ("\r " , "\n " ).strip ()
131+ raw_msg = request .form ["content" ]
132+ msg = raw_msg .replace ("\r \n " , "\n " ).replace ("\r " , "\n " ).strip ()
132133 has_files = any (file .filename for file in files )
133134 if (not has_files and not msg ): return make_json_error (400 , "content or files required" )
134135 replied_to = request .form .get ("replied_to" )
@@ -159,7 +160,8 @@ def sending_messages(db:SQLite, id, channel_id):
159160 public_key , error_resp = public_key_open (user_public_key_data [0 ]["public_key" ])
160161 if error_resp : return error_resp
161162 signed_data = f"{ msg } :{ channel_id } :{ signed_timestamp } "
162- if not rsa_verify_signature (public_key , signature , signed_data ): return make_json_error (400 , "Invalid signature" )
163+ raw_signed_data = f"{ raw_msg .strip ()} :{ channel_id } :{ signed_timestamp } "
164+ if not rsa_verify_signature (public_key , signature , signed_data ) and not rsa_verify_signature (public_key , signature , raw_signed_data ): return make_json_error (400 , "Invalid signature" )
163165 key = None
164166 iv = None
165167 if data ["type" ]!= 3 :
@@ -267,7 +269,8 @@ def message_management(db:SQLite, id, channel_id, message_id):
267269 data = message_channel_data [0 ]
268270 if data ["channel_id" ]!= channel_id : return make_json_error (404 , "Message not found" )
269271 if request .method == "PATCH" :
270- content = request .form .get ("content" )
272+ raw_content = request .form .get ("content" )
273+ content = raw_content
271274 if content is None : return make_json_error (400 , "content is required" )
272275 content = content .replace ("\r \n " , "\n " ).replace ("\r " , "\n " )
273276 if request .form .get ("timestamp" ) is None : return make_json_error (400 , "timestamp is required" )
@@ -285,7 +288,8 @@ def message_management(db:SQLite, id, channel_id, message_id):
285288 public_key , error_resp = public_key_open (user_public_key_data [0 ]["public_key" ])
286289 if error_resp : return error_resp
287290 signed_data = f"{ content } :{ channel_id } :{ signed_timestamp } "
288- if not rsa_verify_signature (public_key , signature , signed_data ): return make_json_error (400 , "Invalid signature" )
291+ raw_signed_data = f"{ raw_content } :{ channel_id } :{ signed_timestamp } "
292+ if not rsa_verify_signature (public_key , signature , signed_data ) and not rsa_verify_signature (public_key , signature , raw_signed_data ): return make_json_error (400 , "Invalid signature" )
289293
290294 if content == data ["content" ] and (data ["type" ]== 3 or request .form .get ("iv" )== data ["iv" ]): return jsonify ({"success" : True })
291295 update_fields = {"content" : content , "edited_at" : timestamp (True ), "signature" : signature , "signed_timestamp" : signed_timestamp }
0 commit comments