X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/f2840d9dd5b8a0683abee189e408c5a6de294eb7..8d8ae609f0201ec4640738ff49b768e899695423:/src/matrix.h diff --git a/src/matrix.h b/src/matrix.h index 5963d7d..b51d0e9 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -11,6 +11,7 @@ #define USER_ID_SIZE 64 +#define ROOM_ID_SIZE 128 #define SERVER_SIZE 20 #define ACCESS_TOKEN_SIZE 40 #define DEVICE_ID_SIZE 20 @@ -50,23 +51,12 @@ #define NUM_OLM_SESSIONS 10 #define NUM_DEVICES 10 -void -Randomize(uint8_t * random, int randomLen); - -bool -JsonEscape( - const char * sIn, int sInLen, - char * sOut, int sOutCap); - -bool JsonSign( - const char * sIn, int sInLen, - char * sOut, int sOutCap); - // Matrix Device typedef struct MatrixDevice { char deviceId[DEVICE_ID_SIZE]; char deviceKey[DEVICE_KEY_SIZE]; + char signingKey[SIGNING_KEY_SIZE]; } MatrixDevice; @@ -81,11 +71,27 @@ 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; @@ -93,7 +99,14 @@ typedef struct MatrixOlmSession { } MatrixOlmSession; bool -MatrixOlmSessionFrom( +MatrixOlmSessionUnpickle( + MatrixOlmSession * session, + const char * deviceId, + void * pickled, int pickledLen, + const void * key, int keyLen); + +bool +MatrixOlmSessionTo( MatrixOlmSession * session, OlmAccount * olmAccount, const char * deviceId, @@ -114,7 +127,7 @@ typedef struct MatrixMegolmInSession { } MatrixMegolmInSession; typedef struct MatrixMegolmOutSession { - const char * roomId; + char roomId[ROOM_ID_SIZE]; OlmOutboundGroupSession * session; char memory[MEGOLM_OUTBOUND_SESSION_MEMORY_SIZE]; @@ -127,13 +140,25 @@ bool MatrixMegolmOutSessionInit( MatrixMegolmOutSession * session, const char * roomId); - + bool MatrixMegolmOutSessionEncrypt( MatrixMegolmOutSession * session, const char * plaintext, char * outBuffer, int outBufferCap); +bool +MatrixMegolmOutSessionSave( + MatrixMegolmOutSession * session, + const char * filename, + const char * key); + +bool +MatrixMegolmOutSessionLoad( + MatrixMegolmOutSession * session, + const char * filename, + const char * key); + // Matrix Client @@ -150,8 +175,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]; @@ -168,6 +193,16 @@ MatrixClientInit( MatrixClient * client, const char * server); +bool +MatrixClientSave( + MatrixClient * client, + const char * filename); + +bool +MatrixClientLoad( + MatrixClient * client, + const char * filename); + bool MatrixClientSetAccessToken( MatrixClient * client, @@ -193,7 +228,7 @@ MatrixClientUploadOnetimeKeys( MatrixClient * client); bool -MatrixClientUploadDeviceKeys( +MatrixClientUploadDeviceKey( MatrixClient * client); bool @@ -239,6 +274,7 @@ MatrixClientShareMegolmOutSession( bool MatrixClientShareMegolmOutSessionTest( MatrixClient * client, + const char * userId, const char * deviceId, MatrixMegolmOutSession * session); @@ -254,6 +290,11 @@ MatrixClientSetMegolmOutSession( const char * roomId, MatrixMegolmOutSession session); +bool +MatrixClientInitMegolmOutSession( + MatrixClient * client, + const char * roomId); + bool MatrixClientGetOlmSession( MatrixClient * client, @@ -278,21 +319,26 @@ MatrixClientSendToDeviceEncrypted( const char * msgType); bool -MatrixClientGetDeviceKey( +MatrixClientRequestDeviceKey( MatrixClient * client, const char * deviceId, char * outDeviceKey, int outDeviceKeyCap); - + bool -MatrixClientGetDeviceKey( +MatrixClientRequestSigningKey( MatrixClient * client, const char * deviceId, - char * outDeviceKey, int outDeviceKeyCap); + char * outSigningKey, int outSigningKeyCap); bool MatrixClientRequestDeviceKeys( MatrixClient * client); +bool +MatrixClientDeleteDevice( + MatrixClient * client); + + bool @@ -330,4 +376,20 @@ MatrixHttpPut( char * outResponseBuffer, int outResponseCap, bool authenticated); +// util + +void +Randomize(uint8_t * random, int randomLen); + +bool +JsonEscape( + const char * sIn, int sInLen, + char * sOut, int sOutCap); + +bool +JsonSign( + MatrixClient * client, + const char * sIn, int sInLen, + char * sOut, int sOutCap); + #endif