X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/07e667e29883740aa0b82199cf0518a2e2684e26..b231872efcb97e52856f5972efd161c6e9b03cd6:/src/matrix.h diff --git a/src/matrix.h b/src/matrix.h index 073f610..4037f09 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -11,12 +11,13 @@ #define USER_ID_SIZE 64 +#define ROOM_ID_SIZE 128 #define SERVER_SIZE 20 #define ACCESS_TOKEN_SIZE 40 #define DEVICE_ID_SIZE 20 #define EXPIRE_MS_SIZE 20 #define REFRESH_TOKEN_SIZE 20 -#define MAX_URL_LEN 128 +#define MAX_URL_LEN 1024 #define OLM_IDENTITY_KEYS_JSON_SIZE 128 #define DEVICE_KEY_SIZE 44 @@ -48,13 +49,14 @@ #define NUM_MEGOLM_SESSIONS 10 #define NUM_OLM_SESSIONS 10 -#define NUM_DEVICES 10 +#define NUM_DEVICES 100 // Matrix Device typedef struct MatrixDevice { char deviceId[DEVICE_ID_SIZE]; char deviceKey[DEVICE_KEY_SIZE]; + char signingKey[SIGNING_KEY_SIZE]; } MatrixDevice; @@ -69,17 +71,48 @@ bool MatrixOlmAccountInit( MatrixOlmAccount * account); +bool +MatrixOlmAccountUnpickle( + MatrixOlmAccount * account, + void * pickled, int pickledLen, + const void * key, int keyLen); + +bool +MatrixOlmAccountGetDeviceKey( + MatrixOlmAccount * account, + char * key, int keyCap); + +bool +MatrixOlmAccountGetSigningKey( + MatrixOlmAccount * account, + char * key, int keyCap); + // Matrix Olm Session typedef struct MatrixOlmSession { - const char * deviceId; + const char * deviceId; // TODO: char[] int type; OlmSession * session; char memory[OLM_SESSION_MEMORY_SIZE]; } MatrixOlmSession; +bool +MatrixOlmSessionUnpickle( + MatrixOlmSession * session, + const char * deviceId, + void * pickled, int pickledLen, + const void * key, int keyLen); + +bool +MatrixOlmSessionFrom( + MatrixOlmSession * session, + OlmAccount * olmAccount, + const char * deviceId, + const char * deviceKey, + const char * encrypted); + bool MatrixOlmSessionTo( MatrixOlmSession * session, @@ -94,21 +127,46 @@ MatrixOlmSessionEncrypt( const char * plaintext, char * outBuffer, int outBufferCap); +bool +MatrixOlmSessionDecrypt( + MatrixOlmSession * session, + size_t messageType, + char * encrypted, + char * outBuffer, int outBufferCap); + // Matrix Megolm Session typedef struct MatrixMegolmInSession { + char roomId[ROOM_ID_SIZE]; + char id[MEGOLM_SESSION_ID_SIZE]; + char key[MEGOLM_SESSION_KEY_SIZE]; + OlmInboundGroupSession * session; + char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE]; + } MatrixMegolmInSession; -typedef struct MatrixMegolmOutSession { - const char * roomId; +bool +MatrixMegolmInSessionInit( + MatrixMegolmInSession * session, + const char * roomId, + const char * sessionId, + const char * sessionKey, int sessionKeyLen); - OlmOutboundGroupSession * session; - char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE]; +bool +MatrixMegolmInSessionDecrypt( + MatrixMegolmInSession * session, + const char * encrypted, int encryptedLen, + char * outDecrypted, int outDecryptedCap); +typedef struct MatrixMegolmOutSession { + char roomId[ROOM_ID_SIZE]; char id[MEGOLM_SESSION_ID_SIZE]; char key[MEGOLM_SESSION_KEY_SIZE]; + + OlmOutboundGroupSession * session; + char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE]; } MatrixMegolmOutSession; bool @@ -150,8 +208,8 @@ typedef struct MatrixClient { MatrixDevice devices[NUM_DEVICES]; int numDevices; - char deviceKey[DEVICE_KEY_SIZE]; - char signingKey[DEVICE_KEY_SIZE]; + // char deviceKey[DEVICE_KEY_SIZE]; + // char signingKey[DEVICE_KEY_SIZE]; char userId[USER_ID_SIZE]; char server[SERVER_SIZE]; @@ -203,7 +261,7 @@ MatrixClientUploadOnetimeKeys( MatrixClient * client); bool -MatrixClientUploadDeviceKeys( +MatrixClientUploadDeviceKey( MatrixClient * client); bool @@ -237,7 +295,15 @@ MatrixClientSendEventEncrypted( bool MatrixClientSync( MatrixClient * client, - char * outSync, int outSyncCap); + char * outSync, int outSyncCap, + const char * nextBatch); + +bool +MatrixClientGetRoomEvent( + MatrixClient * client, + const char * roomId, + const char * eventId, + char * outEvent, int outEventCap); bool MatrixClientShareMegolmOutSession( @@ -249,6 +315,7 @@ MatrixClientShareMegolmOutSession( bool MatrixClientShareMegolmOutSessionTest( MatrixClient * client, + const char * userId, const char * deviceId, MatrixMegolmOutSession * session); @@ -259,13 +326,45 @@ MatrixClientGetMegolmOutSession( MatrixMegolmOutSession ** outSession); bool -MatrixClientSetMegolmOutSession( +MatrixClientNewMegolmOutSession( MatrixClient * client, const char * roomId, - MatrixMegolmOutSession session); + MatrixMegolmOutSession ** outSession); + +bool +MatrixClientGetMegolmInSession( + MatrixClient * client, + const char * roomId, int roomIdLen, + const char * sessionId, int sessionIdLen, + MatrixMegolmInSession ** outSession); bool -MatrixClientGetOlmSession( +MatrixClientNewMegolmInSession( + MatrixClient * client, + const char * roomId, + const char * sessionId, + const char * sessionKey, + MatrixMegolmInSession ** outSession); + +bool +MatrixClientRequestMegolmInSession( + MatrixClient * client, + const char * roomId, + const char * sessionId, + const char * senderKey, + const char * userId, + const char * deviceId); // TODO: remove deviceId (query all devices) + +bool +MatrixClientGetOlmSessionIn( + MatrixClient * client, + const char * userId, + const char * deviceId, + const char * encrypted, + MatrixOlmSession ** outSession); + +bool +MatrixClientGetOlmSessionOut( MatrixClient * client, const char * userId, const char * deviceId, @@ -288,21 +387,31 @@ MatrixClientSendToDeviceEncrypted( const char * msgType); bool -MatrixClientGetDeviceKey( +MatrixClientSendDummy( MatrixClient * client, - const char * deviceId, - char * outDeviceKey, int outDeviceKeyCap); + const char * userId, + const char * deviceId); bool -MatrixClientGetDeviceKey( +MatrixClientRequestDeviceKey( MatrixClient * client, const char * deviceId, char * outDeviceKey, int outDeviceKeyCap); + +bool +MatrixClientRequestSigningKey( + MatrixClient * client, + const char * deviceId, + char * outSigningKey, int outSigningKeyCap); bool MatrixClientRequestDeviceKeys( MatrixClient * client); +bool +MatrixClientDeleteDevice( + MatrixClient * client); + @@ -351,7 +460,13 @@ JsonEscape( const char * sIn, int sInLen, char * sOut, int sOutCap); -bool JsonSign( +bool +JsonCanonicalize( + const char * sIn, int sInLen, + char * sOut, int sOutCap); + +bool +JsonSign( MatrixClient * client, const char * sIn, int sInLen, char * sOut, int sOutCap);