]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix.h
olm session management
[matrix_esp_thesis] / src / matrix.h
index 2e7f6e0e9a6861fa70839a18b2c8dd8ca27b19b4..6538e12d7fa6f16a464d388e11fa41edc18dc44f 100644 (file)
@@ -2,13 +2,15 @@
 #define MATRIX__H\r
 \r
 #include <stdbool.h>\r
 #define MATRIX__H\r
 \r
 #include <stdbool.h>\r
+#include <stdlib.h>\r
 #include <string.h>\r
 #include <string.h>\r
+#include <time.h>\r
 \r
 #include <olm/olm.h>\r
 \r
 \r
 \r
 \r
 #include <olm/olm.h>\r
 \r
 \r
 \r
-// TODO: fix\r
+#define USER_ID_SIZE 64\r
 #define SERVER_SIZE 20\r
 #define ACCESS_TOKEN_SIZE 40\r
 #define DEVICE_ID_SIZE 20\r
 #define SERVER_SIZE 20\r
 #define ACCESS_TOKEN_SIZE 40\r
 #define DEVICE_ID_SIZE 20\r
 #define REFRESH_TOKEN_SIZE 20\r
 #define MAX_URL_LEN 128\r
 \r
 #define REFRESH_TOKEN_SIZE 20\r
 #define MAX_URL_LEN 128\r
 \r
+#define DEVICE_KEY_SIZE 20\r
+\r
+#define KEY_SHARE_EVENT_LEN 1024\r
+\r
+#define OLM_SESSION_MEMORY_SIZE 3352\r
+#define OLM_ENCRYPT_RANDOM_SIZE 32\r
+\r
+#define MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE 232\r
+#define MEGOLM_SESSION_ID_SIZE 44\r
+#define MEGOLM_SESSION_KEY_SIZE 306\r
+#define MEGOLM_INIT_RANDOM_SIZE (4*32 + 32)\r
+\r
+#define NUM_MEGOLM_SESSIONS 10\r
+#define NUM_OLM_SESSIONS 10\r
+#define NUM_DEVICES 10\r
+\r
+void\r
+Randomize(uint8_t * random, int randomLen);\r
+\r
+bool\r
+JsonEscape(\r
+    char * sIn, int sInLen,\r
+    char * sOut, int sOutCap);\r
+\r
+typedef struct MatrixDevice {\r
+    char deviceId[DEVICE_ID_SIZE];\r
+    char deviceKey[DEVICE_KEY_SIZE];\r
+} MatrixDevice;\r
+\r
+typedef struct MatrixOlmSession {\r
+    const char * deviceId;\r
+\r
+    int type;\r
+    OlmSession * session;\r
+    char memory[OLM_SESSION_MEMORY_SIZE];\r
+} MatrixOlmSession;\r
+\r
+bool\r
+MatrixOlmSessionInit(\r
+    MatrixOlmSession * session,\r
+    const char * deviceId);\r
+\r
+bool\r
+MatrixOlmSessionEncrypt(\r
+    MatrixOlmSession * session,\r
+    const char * plaintext,\r
+    char * outBuffer, int outBufferCap);\r
+\r
+\r
+\r
+typedef struct MatrixMegolmInSession {\r
+    OlmInboundGroupSession * session;\r
+} MatrixMegolmInSession;\r
+\r
+typedef struct MatrixMegolmOutSession {\r
+    const char * roomId;\r
+\r
+    OlmOutboundGroupSession * session;\r
+    char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
+\r
+    char id[MEGOLM_SESSION_ID_SIZE];\r
+    char key[MEGOLM_SESSION_KEY_SIZE];\r
+} MatrixMegolmOutSession;\r
+\r
+bool\r
+MatrixMegolmOutSessionInit(\r
+    MatrixMegolmOutSession * session,\r
+    const char * roomId);\r
+    \r
+bool\r
+MatrixMegolmOutSessionEncrypt(\r
+    MatrixMegolmOutSession * session,\r
+    const char * plaintext,\r
+    char * outBuffer, int outBufferCap);\r
+\r
+\r
 \r
 typedef struct MatrixClient {\r
     OlmAccount * olmAccount;\r
     OlmSession * olmSession;\r
 \r
 typedef struct MatrixClient {\r
     OlmAccount * olmAccount;\r
     OlmSession * olmSession;\r
+\r
+    MatrixMegolmInSession megolmInSessions[NUM_MEGOLM_SESSIONS];\r
+    int numMegolmInSessions;\r
+    MatrixMegolmOutSession megolmOutSessions[NUM_MEGOLM_SESSIONS];\r
+    int numMegolmOutSessions;\r
+    MatrixOlmSession olmSessions[NUM_OLM_SESSIONS];\r
+    int numOlmSessions;\r
     \r
     \r
-    char server[SERVER_SIZE+1];\r
-    char accessTokenBuffer[ACCESS_TOKEN_SIZE];\r
-    char deviceIdBuffer[DEVICE_ID_SIZE];\r
-    char expireMsBuffer[EXPIRE_MS_SIZE];\r
-    char refreshTokenBuffer[REFRESH_TOKEN_SIZE];\r
+    MatrixDevice devices[NUM_DEVICES];\r
+    int numDevices;\r
+    \r
+    char deviceKey[DEVICE_KEY_SIZE];\r
+\r
+    char userId[USER_ID_SIZE];\r
+    char server[SERVER_SIZE];\r
+    char accessToken[ACCESS_TOKEN_SIZE];\r
+    char deviceId[DEVICE_ID_SIZE];\r
+    char expireMs[EXPIRE_MS_SIZE];\r
+    char refreshToken[REFRESH_TOKEN_SIZE];\r
 \r
     void * httpUserData;\r
 } MatrixClient;\r
 \r
     void * httpUserData;\r
 } MatrixClient;\r
@@ -53,6 +144,76 @@ MatrixClientSendEvent(
     const char * roomId,\r
     const char * msgType,\r
     const char * msgBody);\r
     const char * roomId,\r
     const char * msgType,\r
     const char * msgBody);\r
+    \r
+bool\r
+MatrixClientSendEventEncrypted(\r
+    MatrixClient * client,\r
+    const char * roomId,\r
+    const char * msgType,\r
+    const char * msgBody);\r
+\r
+bool\r
+MatrixClientSync(\r
+    MatrixClient * client,\r
+    char * outSyncBuffer, int outSyncCap);\r
+\r
+bool\r
+MatrixClientShareMegolmOutSession(\r
+    MatrixClient * client,\r
+    const char * deviceId,\r
+    MatrixMegolmOutSession * session);\r
+\r
+bool\r
+MatrixClientGetMegolmOutSession(\r
+    MatrixClient * client,\r
+    const char * roomId,\r
+    MatrixMegolmOutSession ** outSession);\r
+\r
+bool\r
+MatrixClientSetMegolmOutSession(\r
+    MatrixClient * client,\r
+    const char * roomId,\r
+    MatrixMegolmOutSession session);\r
+\r
+bool\r
+MatrixClientGetOlmSession(\r
+    MatrixClient * client,\r
+    const char * deviceId,\r
+    MatrixOlmSession ** outSession);\r
+\r
+bool\r
+MatrixClientSendToDevice(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    const char * message,\r
+    const char * msgType);\r
+\r
+bool\r
+MatrixClientSendToDeviceEncrypted(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    const char * message,\r
+    const char * msgType);\r
+\r
+bool\r
+MatrixClientGetDeviceKey(\r
+    MatrixClient * client,\r
+    const char * deviceId,\r
+    char * outDeviceKey, int outDeviceKeyCap);\r
+\r
+bool\r
+MatrixClientGetDeviceKey(\r
+    MatrixClient * client,\r
+    const char * deviceId,\r
+    char * outDeviceKey, int outDeviceKeyCap);\r
+\r
+bool\r
+MatrixClientRequestDeviceKeys(\r
+    MatrixClient * client);\r
+\r
+\r
 \r
 bool\r
 MatrixHttpInit(\r
 \r
 bool\r
 MatrixHttpInit(\r