]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - src/matrix.h
remove newline
[matrix_esp_thesis] / src / matrix.h
index 4037f0968705f717c8b6cbd7f17394672662be4b..226a341152b9e298b2984d0086398d3a6a08540c 100644 (file)
@@ -23,6 +23,7 @@
 #define DEVICE_KEY_SIZE 44\r
 #define SIGNING_KEY_SIZE 44\r
 #define ONETIME_KEY_SIZE 44\r
 #define DEVICE_KEY_SIZE 44\r
 #define SIGNING_KEY_SIZE 44\r
 #define ONETIME_KEY_SIZE 44\r
+#define MASTER_KEY_SIZE 44\r
 \r
 #define KEY_SHARE_EVENT_LEN 1024\r
 \r
 \r
 #define KEY_SHARE_EVENT_LEN 1024\r
 \r
 #define JSON_ONETIME_KEY_SIGNED_SIZE 256\r
 #define JSON_SIGNATURE_SIZE 256\r
 \r
 #define JSON_ONETIME_KEY_SIGNED_SIZE 256\r
 #define JSON_SIGNATURE_SIZE 256\r
 \r
-#define NUM_MEGOLM_SESSIONS 10\r
-#define NUM_OLM_SESSIONS 10\r
-#define NUM_DEVICES 100\r
+#define NUM_MEGOLM_SESSIONS 2\r
+#define NUM_OLM_SESSIONS 2\r
+#define NUM_DEVICES 10\r
+\r
+// HTTP\r
+\r
+typedef struct MatrixHttpConnection MatrixHttpConnection;\r
+\r
+bool\r
+MatrixHttpInit(\r
+    MatrixHttpConnection ** hc,\r
+    const char * host);\r
+\r
+bool\r
+MatrixHttpDeinit(\r
+    MatrixHttpConnection ** hc);\r
+    \r
+bool\r
+MatrixHttpSetAccessToken(\r
+    MatrixHttpConnection * hc,\r
+    const char * accessToken);\r
+\r
+bool\r
+MatrixHttpGet(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+bool\r
+MatrixHttpPost(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    const char * requestBuffer,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+bool\r
+MatrixHttpPut(\r
+    MatrixHttpConnection * hc,\r
+    const char * url,\r
+    const char * requestBuffer,\r
+    char * outResponseBuffer, int outResponseCap,\r
+    bool authenticated);\r
+\r
+\r
 \r
 // Matrix Device\r
 \r
 \r
 // Matrix Device\r
 \r
@@ -105,6 +149,7 @@ MatrixOlmSessionUnpickle(
     void * pickled, int pickledLen,\r
     const void * key, int keyLen);\r
 \r
     void * pickled, int pickledLen,\r
     const void * key, int keyLen);\r
 \r
+// create an olm sesseion from a type 0 message\r
 bool\r
 MatrixOlmSessionFrom(\r
     MatrixOlmSession * session,\r
 bool\r
 MatrixOlmSessionFrom(\r
     MatrixOlmSession * session,\r
@@ -113,6 +158,7 @@ MatrixOlmSessionFrom(
     const char * deviceKey,\r
     const char * encrypted);\r
 \r
     const char * deviceKey,\r
     const char * encrypted);\r
 \r
+// create a new olm session from a claimed onetime key\r
 bool\r
 MatrixOlmSessionTo(\r
     MatrixOlmSession * session,\r
 bool\r
 MatrixOlmSessionTo(\r
     MatrixOlmSession * session,\r
@@ -180,18 +226,6 @@ MatrixMegolmOutSessionEncrypt(
     const char * plaintext,\r
     char * outBuffer, int outBufferCap);\r
 \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
@@ -207,34 +241,22 @@ typedef struct MatrixClient {
     \r
     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
 \r
     char userId[USER_ID_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
     char accessToken[ACCESS_TOKEN_SIZE];\r
     char deviceId[DEVICE_ID_SIZE];\r
     char expireMs[EXPIRE_MS_SIZE];\r
     char refreshToken[REFRESH_TOKEN_SIZE];\r
+    char masterKey[MASTER_KEY_SIZE];\r
 \r
 \r
-    void * httpUserData;\r
+    bool verified;\r
+\r
+    MatrixHttpConnection * hc;\r
 } MatrixClient;\r
 \r
 bool\r
 MatrixClientInit(\r
 } MatrixClient;\r
 \r
 bool\r
 MatrixClientInit(\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
+    MatrixClient * client);\r
 \r
 bool\r
 MatrixClientSetAccessToken(\r
 \r
 bool\r
 MatrixClientSetAccessToken(\r
@@ -261,7 +283,7 @@ MatrixClientUploadOnetimeKeys(
     MatrixClient * client);\r
 \r
 bool\r
     MatrixClient * client);\r
 \r
 bool\r
-MatrixClientUploadDeviceKey(\r
+MatrixClientUploadDeviceKeys(\r
     MatrixClient * client);\r
 \r
 bool\r
     MatrixClient * client);\r
 \r
 bool\r
@@ -295,8 +317,8 @@ MatrixClientSendEventEncrypted(
 bool\r
 MatrixClientSync(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientSync(\r
     MatrixClient * client,\r
-    char * outSync, int outSyncCap,\r
-    const char * nextBatch);\r
+    char * outSyncBuffer, int outSyncCap,\r
+    char * nextBatch, int nextBatchCap);\r
 \r
 bool\r
 MatrixClientGetRoomEvent(\r
 \r
 bool\r
 MatrixClientGetRoomEvent(\r
@@ -312,25 +334,21 @@ MatrixClientShareMegolmOutSession(
     const char * deviceId,\r
     MatrixMegolmOutSession * session);\r
 \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
+// try to lookup outgoing megolm session, return true if found\r
 bool\r
 MatrixClientGetMegolmOutSession(\r
     MatrixClient * client,\r
     const char * roomId,\r
     MatrixMegolmOutSession ** outSession);\r
 \r
 bool\r
 MatrixClientGetMegolmOutSession(\r
     MatrixClient * client,\r
     const char * roomId,\r
     MatrixMegolmOutSession ** outSession);\r
 \r
+// create a new outgoing megolm session and store it locally\r
 bool\r
 MatrixClientNewMegolmOutSession(\r
     MatrixClient * client,\r
     const char * roomId,\r
     MatrixMegolmOutSession ** outSession);\r
 \r
 bool\r
 MatrixClientNewMegolmOutSession(\r
     MatrixClient * client,\r
     const char * roomId,\r
     MatrixMegolmOutSession ** outSession);\r
 \r
+// try to lookup incoming megolm session, return true if found\r
 bool\r
 MatrixClientGetMegolmInSession(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientGetMegolmInSession(\r
     MatrixClient * client,\r
@@ -338,6 +356,7 @@ MatrixClientGetMegolmInSession(
     const char * sessionId, int sessionIdLen,\r
     MatrixMegolmInSession ** outSession);\r
 \r
     const char * sessionId, int sessionIdLen,\r
     MatrixMegolmInSession ** outSession);\r
 \r
+// create a new incoming megolm session and store it locally\r
 bool\r
 MatrixClientNewMegolmInSession(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientNewMegolmInSession(\r
     MatrixClient * client,\r
@@ -345,7 +364,8 @@ MatrixClientNewMegolmInSession(
     const char * sessionId,\r
     const char * sessionKey,\r
     MatrixMegolmInSession ** outSession);\r
     const char * sessionId,\r
     const char * sessionKey,\r
     MatrixMegolmInSession ** outSession);\r
-    \r
+\r
+// send a m.room_key_request to the device identified by userId/devideId\r
 bool\r
 MatrixClientRequestMegolmInSession(\r
     MatrixClient * client,\r
 bool\r
 MatrixClientRequestMegolmInSession(\r
     MatrixClient * client,\r
@@ -353,18 +373,29 @@ MatrixClientRequestMegolmInSession(
     const char * sessionId,\r
     const char * senderKey,\r
     const char * userId,\r
     const char * sessionId,\r
     const char * senderKey,\r
     const char * userId,\r
-    const char * deviceId); // TODO: remove deviceId (query all devices)\r
+    const char * deviceId);\r
 \r
 \r
+// try to lookup olm session, return true if found\r
 bool\r
 bool\r
-MatrixClientGetOlmSessionIn(\r
+MatrixClientGetOlmSession(\r
+    MatrixClient * client,\r
+    const char * userId,\r
+    const char * deviceId,\r
+    MatrixOlmSession ** outSession);\r
+\r
+// create a new olm session from a type 0 message and store it locally\r
+bool\r
+MatrixClientNewOlmSessionIn(\r
     MatrixClient * client,\r
     const char * userId,\r
     const char * deviceId,\r
     const char * encrypted,\r
     MatrixOlmSession ** outSession);\r
     MatrixClient * client,\r
     const char * userId,\r
     const char * deviceId,\r
     const char * encrypted,\r
     MatrixOlmSession ** outSession);\r
-    \r
+\r
+// create a new olm session with device userId/deviceId and store it locally\r
+// this automatically claims the onetime key\r
 bool\r
 bool\r
-MatrixClientGetOlmSessionOut(\r
+MatrixClientNewOlmSessionOut(\r
     MatrixClient * client,\r
     const char * userId,\r
     const char * deviceId,\r
     MatrixClient * client,\r
     const char * userId,\r
     const char * deviceId,\r
@@ -392,63 +423,37 @@ MatrixClientSendDummy(
     const char * userId,\r
     const char * deviceId);\r
 \r
     const char * userId,\r
     const char * deviceId);\r
 \r
+// lookup device key locally and if not present get it from server\r
 bool\r
 MatrixClientRequestDeviceKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outDeviceKey, int outDeviceKeyCap);\r
     \r
 bool\r
 MatrixClientRequestDeviceKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outDeviceKey, int outDeviceKeyCap);\r
     \r
+// lookup signing key locally and if not present get it from server\r
 bool\r
 MatrixClientRequestSigningKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outSigningKey, int outSigningKeyCap);\r
 \r
 bool\r
 MatrixClientRequestSigningKey(\r
     MatrixClient * client,\r
     const char * deviceId,\r
     char * outSigningKey, int outSigningKeyCap);\r
 \r
+// lookup the master key for this user and if not present get it from server\r
 bool\r
 bool\r
-MatrixClientRequestDeviceKeys(\r
-    MatrixClient * client);\r
-\r
-bool\r
-MatrixClientDeleteDevice(\r
-    MatrixClient * client);\r
-\r
-\r
-\r
-\r
-bool\r
-MatrixHttpInit(\r
-    MatrixClient * client);\r
+MatrixClientRequestMasterKey(\r
+    MatrixClient * client,\r
+    char * outMasterKey, int outMasterKeyCap);\r
 \r
 \r
+// call keys/query and store retrieved information\r
+// this is called by the other Request* functions\r
 bool\r
 bool\r
-MatrixHttpConnect(\r
+MatrixClientRequestDeviceKeys(\r
     MatrixClient * client);\r
 \r
     MatrixClient * client);\r
 \r
+// delete this device on the server\r
 bool\r
 bool\r
-MatrixHttpDeinit(\r
+MatrixClientDeleteDevice(\r
     MatrixClient * client);\r
 \r
     MatrixClient * client);\r
 \r
-bool\r
-MatrixHttpGet(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
-\r
-bool\r
-MatrixHttpPost(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    const char * requestBuffer,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
-\r
-bool\r
-MatrixHttpPut(\r
-    MatrixClient * client,\r
-    const char * url,\r
-    const char * requestBuffer,\r
-    char * outResponseBuffer, int outResponseCap,\r
-    bool authenticated);\r
 \r
 // util\r
 \r
 \r
 // util\r
 \r