okTurtles / group-income

A decentralized and private (end-to-end encrypted) financial safety net for you and your friends.
https://groupincome.org
GNU Affero General Public License v3.0
331 stars 44 forks source link

Fix invalid key error #2332

Open corrideat opened 2 months ago

corrideat commented 2 months ago

Problem

Just before merging PR #2294, a ChelErrorSignatureKeyUnauthorized error was thrown. This is a serious error indicating key management issues that will result in degraded user experience.

The error manifested in the second attempt of the pre-merge GitHub action run.

From the corresponding logs, the following could be inferred:

Error

["error","[chelonia] ERROR 'ChelErrorSignatureKeyUnauthorized' in processMutation for
<op_ae|z9brRu3VKBEb7nxkHShu1Usg4aQvKmAAcuotb4xT7LJFAwFYtYSK
of z9brRu3VLst3nZSbPnf4d53s3zb4nS1mmcCW7Wf6wSmtzLSw6Ddz>:
Key z2DrjgbDaRKraoj7qSStdtA3weZ6WrL4S4LqnXaTZn3Stud4rjm is unauthorized or expired
for the current contract",{"name":"ChelErrorSignatureKeyUnauthorized"}]

Message affected

Message contents

"{\"_signedData\":[\"[\\\"z2DrjgbGyqJxXs1xuEHSN71gB6SyF8jAZkksRFrv3ie2GorHJgn\\\",\\\"Woi1N8tod/O8RCSzZYflcXfSSuby7wsOB7wKQvB7Xx0/PpOIZ2y9HbDG1KJASqJFoSEfEM9gxL0yEsbpit4U1NRXKBkLaX4mcui1fIoDGir2mGwdMNn+VnUB/d+HMXy/DaLjMPL0npbeC8v1IPRz8UcQ8xqm1jAm89DI8To9PCG7QgHI1NAnpZPXikdmBg/0ComO6IQGggNRHkZG9f5+GJmHizUtFBYNdBcnPV8zSCF9tgGUcwuzEKulBmxR/mVnASzJIj8XjaI6yH4NDQWeSOoYxoAW4hxmc68wcOMjqVJBJlg+Tk3FEY43rLm3BVS6Fm8OWpFgGDLetzB54Ae4J0CN5q1kdi/nSHwEYf9DzJk4s8tz/k7q2khlwwh/zB6ct8Wi9JQP+5GcUg4i21m5DrEJ/lSD/D1ig2yncTKc4/n5ntJ9jOhdbDJMKEoRiDtvULSGZRaF67IfvbC0RQctJZ252HZHEY7u8MFtAm/Mh1/P8oIyAWkPjzPfQwc50PwiDxmoeXREBXaRHZB36+T1/UqNzGBF3RZQ3jEYNVBDm+SMPQBAsctRdPVFpCJKAAIeh6mjBkDqv4OawkIESj4MKvZB9b2CQ9q9pJ5u66rN4Q71zM6vEAoPUVQa5IMbiz5fAnUSW4FQQ2eN106F4z80pV9ZlbgzDaqoljsdePWc3L+gwG2IrMps+4VEYMVE+lPFYE31OCpIQwez9nAIdCEhLFWpM7eGwdM4OVjF12wdHZLu2OwEDeJ2tgb1Oum1LeSymDAdXrLIYxoA00qu9ym0pJ7Sni/rELUpLw/IT8M1ss/rdELOLntQrg1W0gxLLA6eOW/IXLGtzhXj7M4OXNYX3djQkWxSn44/GQyeurTSWjlIKdhntX9lzQQMksrKcoYERv+eaCk96f1CQj9jti7sLt6uhFV8TYFX/2zjMNw+oCUeKgfSQQQduVALnMVU3Tt/+prDAYfaoWgVs7wTkbmqDIL5acLkbBl1Or5h11Fko8DNYZRFMl8jFGBkKTMXsZjqdoc0nIQ8Spo3ib0giLpueXjGrBs2MX4SPb+O1qc=\\\"]\",\"z2Drjgb6zEo7EJPasjeqAh5gDi8JyQ2A3ZLpPjQMB5AXcoSjBcr\",\"hBqM121V+lfO2KqSHmfGe7A80tjAL5QzbFG1ZgaEUKLp4RVcUXjEiwpyuzjcGMJ65G1uAXRlemaEE/fg31jdAw==\"],\"head\":\"{\\\"version\\\":\\\"1.0.0\\\",\\\"previousHEAD\\\":\\\"z9brRu3VR32qYmTCCtW6epVZ8sWW5cqLtXzp5tuEFNDS7cEPr2zK\\\",\\\"height\\\":8,\\\"contractID\\\":\\\"z9brRu3VLst3nZSbPnf4d53s3zb4nS1mmcCW7Wf6wSmtzLSw6Ddz\\\",\\\"op\\\":\\\"ae\\\",\\\"manifest\\\":\\\"z9brRu3VGby9M96GhT9DQdC8bDeV3csU5dX2AEY4dTKVJRbURiHY\\\"}\"}"
Inner payload (decrypted)
{"_signedData":["{\\"action\\":\\"gi.contracts/chatroom/addMessage\\",\\"data\\":{\\"type\\":\\"interactive\\",\\"proposal\\":{\\"proposalType\\":\\"remove-member\\",\\"proposalData\\":{\\"memberID\\":\\"z9brRu3VMc1WMhzBwM3p5ogvy4fCNX5ezfFiiDtqXk8JBjuiF6b4\\",\\"reason\\":\\"I think it is a bot!\\"},\\"expires_date_ms\\":1726777536087,\\"createdDate\\":\\"2024-09-05T20:25:36.092Z\\",\\"creatorID\\":\\"z9brRu3VUVse7woMHoc9KQwEzoi9jamWeVdf3UuK9wqfBzucpb4u\\",\\"proposalId\\":\\"z9brRu3VWq4uSpEXXBGbhiYd51VovnpQCgjS7NtGYT48NBQi8hih\\",\\"status\\":\\"passed\\"}},\\"meta\\":{\\"createdDate\\":\\"2024-09-05T20:25:40.339Z\\"}}","z2DrjgbDaRKraoj7qSStdtA3weZ6WrL4S4LqnXaTZn3Stud4rjm","uL8s/Q156MbLcNRNt/DJfGSsFdQy9+U5CxzsKdgXJh2x6QK+ftO6QYhYJSME632JLeTUNVW4m/t4kuRBvvqFBA=="]}

Stacktrace

2024-09-05T20:25:53.0467132Z       at Object.verifySignatureData (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:7727:22)
2024-09-05T20:25:53.0468111Z       at Object.verifySignedValueFn (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:7826:45)
2024-09-05T20:25:53.0469050Z       at validateActionPermissions (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:8625:40)
2024-09-05T20:25:53.0469977Z       at validateKeyPermissions (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:8655:81)
2024-09-05T20:25:53.0471224Z       at Object.chelonia/private/in/processMessage (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:10014:12)
2024-09-05T20:25:53.0472198Z       at sbp (http://127.0.0.1:8000/assets/js/chunk-MN2RILWH-cached.js:32:25)
2024-09-05T20:25:53.0473049Z       at Object.processMutation (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:10530:11)
2024-09-05T20:25:53.0474077Z       at Object.chelonia/private/in/handleEvent (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:10434:43)
2024-09-05T20:25:53.0474973Z       at sbp (http://127.0.0.1:8000/assets/js/chunk-MN2RILWH-cached.js:32:25)
2024-09-05T20:25:53.0475901Z       at Object.chelonia/private/in/syncContract (http://127.0.0.1:8000/assets/js/chunk-CWIVWHQ5-cached.js:10076:17)

Problem diagnosis

When user2 votes on the proposal to remove userBot, it sends a message to the #general chatroom as the proposal passes.

A previous test was for user2 to join the group, leave and then re-join. It seems that, at least from the perspective of user1 and userBot (need to confirm whether this also was the case for user2), the action to re-join the #general chatroom was never processed (this could be due to a processing error or due to it never having been sent).

The video of the run, at around the 1:00 mark, shows that user2 has left #general but hasn't rejoined.

As a result, when user2 sends this message, the inner payload uses an inner signing key that has been revoked (when user2 left the group). This triggers the error in question, as expected. The correct behaviour in this case would be to make sure that user2 rejoins the #general chatroom when re-joining a group, and that this action is correctly processed by all members.

Solution

As noted, the error is expected due to another underlying error (user2 not rejoining the #general chatroom). The solution is to diagnose why this happened and address this situation so that it doesn't happen.