]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix.h
able to send encrypted messages :)
[matrix_esp_thesis] / src / matrix.h
index 72e865ff81c8e2f35c39c9fb358aa90dfaefa498..b51d0e99fc3469c612d21e09fd6c5312f7be0324 100644 (file)
@@ -11,6 +11,7 @@
 \r
 \r
 #define USER_ID_SIZE 64\r
 \r
 \r
 #define USER_ID_SIZE 64\r
+#define ROOM_ID_SIZE 128\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
@@ -21,6 +22,7 @@
 #define OLM_IDENTITY_KEYS_JSON_SIZE 128\r
 #define DEVICE_KEY_SIZE 44\r
 #define SIGNING_KEY_SIZE 44\r
 #define OLM_IDENTITY_KEYS_JSON_SIZE 128\r
 #define DEVICE_KEY_SIZE 44\r
 #define SIGNING_KEY_SIZE 44\r
+#define ONETIME_KEY_SIZE 44\r
 \r
 #define KEY_SHARE_EVENT_LEN 1024\r
 \r
 \r
 #define KEY_SHARE_EVENT_LEN 1024\r
 \r
@@ -29,8 +31,9 @@
 \r
 #define OLM_SESSION_MEMORY_SIZE 3352\r
 #define OLM_ENCRYPT_RANDOM_SIZE 32\r
 \r
 #define OLM_SESSION_MEMORY_SIZE 3352\r
 #define OLM_ENCRYPT_RANDOM_SIZE 32\r
+#define OLM_OUTBOUND_SESSION_RANDOM_SIZE (32*2)\r
 \r
 \r
-#define OLM_ONETIME_KEYS_RANDOM_SIZE 32*10\r
+#define OLM_ONETIME_KEYS_RANDOM_SIZE (32*10)\r
 #define OLM_KEY_ID_SIZE 32\r
 \r
 #define OLM_SIGNATURE_SIZE 128\r
 #define OLM_KEY_ID_SIZE 32\r
 \r
 #define OLM_SIGNATURE_SIZE 128\r
 #define NUM_OLM_SESSIONS 10\r
 #define NUM_DEVICES 10\r
 \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
-bool JsonSign(\r
-    char * sIn, int sInLen,\r
-    char * sOut, int sOutCap);\r
-\r
 // Matrix Device\r
 \r
 typedef struct MatrixDevice {\r
     char deviceId[DEVICE_ID_SIZE];\r
     char deviceKey[DEVICE_KEY_SIZE];\r
 // Matrix Device\r
 \r
 typedef struct MatrixDevice {\r
     char deviceId[DEVICE_ID_SIZE];\r
     char deviceKey[DEVICE_KEY_SIZE];\r
+    char signingKey[SIGNING_KEY_SIZE];\r
 } MatrixDevice;\r
 \r
 \r
 } MatrixDevice;\r
 \r
 \r
@@ -79,11 +71,27 @@ bool
 MatrixOlmAccountInit(\r
     MatrixOlmAccount * account);\r
 \r
 MatrixOlmAccountInit(\r
     MatrixOlmAccount * account);\r
 \r
+bool\r
+MatrixOlmAccountUnpickle(\r
+    MatrixOlmAccount * account,\r
+    void * pickled, int pickledLen,\r
+    const void * key, int keyLen);\r
+\r
+bool\r
+MatrixOlmAccountGetDeviceKey(\r
+    MatrixOlmAccount * account,\r
+    char * key, int keyCap);\r
+    \r
+bool\r
+MatrixOlmAccountGetSigningKey(\r
+    MatrixOlmAccount * account,\r
+    char * key, int keyCap);\r
+\r
 \r
 // Matrix Olm Session\r
 \r
 typedef struct MatrixOlmSession {\r
 \r
 // Matrix Olm Session\r
 \r
 typedef struct MatrixOlmSession {\r
-    const char * deviceId;\r
+    const char * deviceId; // TODO: char[]\r
 \r
     int type;\r
     OlmSession * session;\r
 \r
     int type;\r
     OlmSession * session;\r
@@ -91,9 +99,19 @@ typedef struct MatrixOlmSession {
 } MatrixOlmSession;\r
 \r
 bool\r
 } MatrixOlmSession;\r
 \r
 bool\r
-MatrixOlmSessionInit(\r
+MatrixOlmSessionUnpickle(\r
     MatrixOlmSession * session,\r
     MatrixOlmSession * session,\r
-    const char * deviceId);\r
+    const char * deviceId,\r
+    void * pickled, int pickledLen,\r
+    const void * key, int keyLen);\r
+\r
+bool\r
+MatrixOlmSessionTo(\r
+    MatrixOlmSession * session,\r
+    OlmAccount * olmAccount,\r
+    const char * deviceId,\r
+    const char * deviceKey,\r
+    const char * deviceOnetimeKey);\r
 \r
 bool\r
 MatrixOlmSessionEncrypt(\r
 \r
 bool\r
 MatrixOlmSessionEncrypt(\r
@@ -109,7 +127,7 @@ typedef struct MatrixMegolmInSession {
 } MatrixMegolmInSession;\r
 \r
 typedef struct MatrixMegolmOutSession {\r
 } MatrixMegolmInSession;\r
 \r
 typedef struct MatrixMegolmOutSession {\r
-    const char * roomId;\r
+    char roomId[ROOM_ID_SIZE];\r
 \r
     OlmOutboundGroupSession * session;\r
     char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
 \r
     OlmOutboundGroupSession * session;\r
     char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE];\r
@@ -122,13 +140,25 @@ bool
 MatrixMegolmOutSessionInit(\r
     MatrixMegolmOutSession * session,\r
     const char * roomId);\r
 MatrixMegolmOutSessionInit(\r
     MatrixMegolmOutSession * session,\r
     const char * roomId);\r
-    \r
+\r
 bool\r
 MatrixMegolmOutSessionEncrypt(\r
     MatrixMegolmOutSession * session,\r
     const char * plaintext,\r
     char * outBuffer, int outBufferCap);\r
 \r
 bool\r
 MatrixMegolmOutSessionEncrypt(\r
     MatrixMegolmOutSession * session,\r
     const char * plaintext,\r
     char * outBuffer, int outBufferCap);\r
 \r
+bool\r
+MatrixMegolmOutSessionSave(\r
+    MatrixMegolmOutSession * session,\r
+    const char * filename,\r
+    const char * key);\r
+    \r
+bool\r
+MatrixMegolmOutSessionLoad(\r
+    MatrixMegolmOutSession * session,\r
+    const char * filename,\r
+    const char * key);\r
+\r
 \r
 // Matrix Client\r
 \r
 \r
 // Matrix Client\r
 \r
@@ -145,8 +175,8 @@ typedef struct MatrixClient {
     MatrixDevice devices[NUM_DEVICES];\r
     int numDevices;\r
     \r
     MatrixDevice devices[NUM_DEVICES];\r
     int numDevices;\r
     \r
-    char deviceKey[DEVICE_KEY_SIZE];\r
-    char signingKey[DEVICE_KEY_SIZE];\r
+    // char deviceKey[DEVICE_KEY_SIZE];\r
+    // char signingKey[DEVICE_KEY_SIZE];\r
 \r
     char userId[USER_ID_SIZE];\r
     char server[SERVER_SIZE];\r
 \r
     char userId[USER_ID_SIZE];\r
     char server[SERVER_SIZE];\r
@@ -163,6 +193,16 @@ MatrixClientInit(
     MatrixClient * client,\r
     const char * server);\r
 \r
     MatrixClient * client,\r
     const char * server);\r
 \r
+bool\r
+MatrixClientSave(\r
+    MatrixClient * client,\r
+    const char * filename);\r
+\r
+bool\r
+MatrixClientLoad(\r
+    MatrixClient * client,\r
+    const char * filename);\r
+\r
 bool\r
 MatrixClientSetAccessToken(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientSetAccessToken(\r
     MatrixClient * client,\r
@@ -188,9 +228,16 @@ MatrixClientUploadOnetimeKeys(
     MatrixClient * client);\r
 \r
 bool\r
     MatrixClient * client);\r
 \r
 bool\r
-MatrixClientUploadDeviceKeys(\r
+MatrixClientUploadDeviceKey(\r
     MatrixClient * client);\r
 \r
     MatrixClient * client);\r
 \r
+bool\r
+MatrixClientClaimOnetimeKey(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    char * outOnetimeKey, int outOnetimeKeyCap);\r
+\r
 bool\r
 MatrixClientLoginPassword(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientLoginPassword(\r
     MatrixClient * client,\r
@@ -215,17 +262,19 @@ MatrixClientSendEventEncrypted(
 bool\r
 MatrixClientSync(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientSync(\r
     MatrixClient * client,\r
-    char * outSyncBuffer, int outSyncCap);\r
+    char * outSync, int outSyncCap);\r
 \r
 bool\r
 MatrixClientShareMegolmOutSession(\r
     MatrixClient * client,\r
 \r
 bool\r
 MatrixClientShareMegolmOutSession(\r
     MatrixClient * client,\r
+    const char * userId,\r
     const char * deviceId,\r
     MatrixMegolmOutSession * session);\r
 \r
 bool\r
 MatrixClientShareMegolmOutSessionTest(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     MatrixMegolmOutSession * session);\r
 \r
 bool\r
 MatrixClientShareMegolmOutSessionTest(\r
     MatrixClient * client,\r
+    const char * userId,\r
     const char * deviceId,\r
     MatrixMegolmOutSession * session);\r
 \r
     const char * deviceId,\r
     MatrixMegolmOutSession * session);\r
 \r
@@ -241,9 +290,15 @@ MatrixClientSetMegolmOutSession(
     const char * roomId,\r
     MatrixMegolmOutSession session);\r
 \r
     const char * roomId,\r
     MatrixMegolmOutSession session);\r
 \r
+bool\r
+MatrixClientInitMegolmOutSession(\r
+    MatrixClient * client,\r
+    const char * roomId);\r
+\r
 bool\r
 MatrixClientGetOlmSession(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientGetOlmSession(\r
     MatrixClient * client,\r
+    const char * userId,\r
     const char * deviceId,\r
     MatrixOlmSession ** outSession);\r
 \r
     const char * deviceId,\r
     MatrixOlmSession ** outSession);\r
 \r
@@ -264,21 +319,26 @@ MatrixClientSendToDeviceEncrypted(
     const char * msgType);\r
 \r
 bool\r
     const char * msgType);\r
 \r
 bool\r
-MatrixClientGetDeviceKey(\r
+MatrixClientRequestDeviceKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outDeviceKey, int outDeviceKeyCap);\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outDeviceKey, int outDeviceKeyCap);\r
-\r
+    \r
 bool\r
 bool\r
-MatrixClientGetDeviceKey(\r
+MatrixClientRequestSigningKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     MatrixClient * client,\r
     const char * deviceId,\r
-    char * outDeviceKey, int outDeviceKeyCap);\r
+    char * outSigningKey, int outSigningKeyCap);\r
 \r
 bool\r
 MatrixClientRequestDeviceKeys(\r
     MatrixClient * client);\r
 \r
 \r
 bool\r
 MatrixClientRequestDeviceKeys(\r
     MatrixClient * client);\r
 \r
+bool\r
+MatrixClientDeleteDevice(\r
+    MatrixClient * client);\r
+\r
+\r
 \r
 \r
 bool\r
 \r
 \r
 bool\r
@@ -316,4 +376,20 @@ MatrixHttpPut(
     char * outResponseBuffer, int outResponseCap,\r
     bool authenticated);\r
 \r
     char * outResponseBuffer, int outResponseCap,\r
     bool authenticated);\r
 \r
+// util\r
+\r
+void\r
+Randomize(uint8_t * random, int randomLen);\r
+\r
+bool\r
+JsonEscape(\r
+    const char * sIn, int sInLen,\r
+    char * sOut, int sOutCap);\r
+    \r
+bool\r
+JsonSign(\r
+    MatrixClient * client,\r
+    const char * sIn, int sInLen,\r
+    char * sOut, int sOutCap);\r
+\r
 #endif\r
 #endif\r