X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/8d8ae609f0201ec4640738ff49b768e899695423..b231ec39ba5b9df6288a50204e5dabe9f591c830:/src/matrix.h diff --git a/src/matrix.h b/src/matrix.h index b51d0e9..c07c742 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -17,7 +17,7 @@ #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 @@ -47,9 +47,56 @@ #define JSON_ONETIME_KEY_SIGNED_SIZE 256 #define JSON_SIGNATURE_SIZE 256 -#define NUM_MEGOLM_SESSIONS 10 -#define NUM_OLM_SESSIONS 10 -#define NUM_DEVICES 10 +#define NUM_MEGOLM_SESSIONS 2 +#define NUM_OLM_SESSIONS 2 +#define NUM_DEVICES 5 + +// HTTP + +typedef struct MatrixHttpConnection MatrixHttpConnection; + +bool +MatrixHttpInit( + MatrixHttpConnection ** hc, + const char * host); + +// bool +// MatrixHttpConnect( +// MatrixHttpConnection * hc); + +bool +MatrixHttpDeinit( + MatrixHttpConnection ** hc); + +bool +MatrixHttpSetAccessToken( + MatrixHttpConnection * hc, + const char * accessToken); + +bool +MatrixHttpGet( + MatrixHttpConnection * hc, + const char * url, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + +bool +MatrixHttpPost( + MatrixHttpConnection * hc, + const char * url, + const char * requestBuffer, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + +bool +MatrixHttpPut( + MatrixHttpConnection * hc, + const char * url, + const char * requestBuffer, + char * outResponseBuffer, int outResponseCap, + bool authenticated); + + // Matrix Device @@ -105,6 +152,14 @@ MatrixOlmSessionUnpickle( 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, @@ -119,21 +174,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; +bool +MatrixMegolmInSessionInit( + MatrixMegolmInSession * session, + const char * roomId, + const char * sessionId, + const char * sessionKey, int sessionKeyLen); + +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]; - - char id[MEGOLM_SESSION_ID_SIZE]; - char key[MEGOLM_SESSION_KEY_SIZE]; } MatrixMegolmOutSession; bool @@ -179,19 +259,17 @@ typedef struct MatrixClient { // char signingKey[DEVICE_KEY_SIZE]; char userId[USER_ID_SIZE]; - char server[SERVER_SIZE]; char accessToken[ACCESS_TOKEN_SIZE]; char deviceId[DEVICE_ID_SIZE]; char expireMs[EXPIRE_MS_SIZE]; char refreshToken[REFRESH_TOKEN_SIZE]; - void * httpUserData; + MatrixHttpConnection * hc; } MatrixClient; bool MatrixClientInit( - MatrixClient * client, - const char * server); + MatrixClient * client); bool MatrixClientSave( @@ -262,7 +340,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( @@ -285,15 +371,34 @@ MatrixClientGetMegolmOutSession( MatrixMegolmOutSession ** outSession); bool -MatrixClientSetMegolmOutSession( +MatrixClientNewMegolmOutSession( MatrixClient * client, const char * roomId, - MatrixMegolmOutSession session); + MatrixMegolmOutSession ** outSession); bool -MatrixClientInitMegolmOutSession( +MatrixClientGetMegolmInSession( MatrixClient * client, - const char * roomId); + const char * roomId, int roomIdLen, + const char * sessionId, int sessionIdLen, + MatrixMegolmInSession ** outSession); + +bool +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 MatrixClientGetOlmSession( @@ -302,6 +407,21 @@ MatrixClientGetOlmSession( const char * deviceId, MatrixOlmSession ** outSession); +bool +MatrixClientNewOlmSessionIn( + MatrixClient * client, + const char * userId, + const char * deviceId, + const char * encrypted, + MatrixOlmSession ** outSession); + +bool +MatrixClientNewOlmSessionOut( + MatrixClient * client, + const char * userId, + const char * deviceId, + MatrixOlmSession ** outSession); + bool MatrixClientSendToDevice( MatrixClient * client, @@ -318,6 +438,12 @@ MatrixClientSendToDeviceEncrypted( const char * message, const char * msgType); +bool +MatrixClientSendDummy( + MatrixClient * client, + const char * userId, + const char * deviceId); + bool MatrixClientRequestDeviceKey( MatrixClient * client, @@ -339,43 +465,6 @@ MatrixClientDeleteDevice( MatrixClient * client); - - -bool -MatrixHttpInit( - MatrixClient * client); - -bool -MatrixHttpConnect( - MatrixClient * client); - -bool -MatrixHttpDeinit( - MatrixClient * client); - -bool -MatrixHttpGet( - MatrixClient * client, - const char * url, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - -bool -MatrixHttpPost( - MatrixClient * client, - const char * url, - const char * requestBuffer, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - -bool -MatrixHttpPut( - MatrixClient * client, - const char * url, - const char * requestBuffer, - char * outResponseBuffer, int outResponseCap, - bool authenticated); - // util void @@ -386,6 +475,11 @@ JsonEscape( const char * sIn, int sInLen, char * sOut, int sOutCap); +bool +JsonCanonicalize( + const char * sIn, int sInLen, + char * sOut, int sOutCap); + bool JsonSign( MatrixClient * client,