X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/b231ec39ba5b9df6288a50204e5dabe9f591c830..HEAD:/src/matrix.h diff --git a/src/matrix.h b/src/matrix.h index c07c742..226a341 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -23,6 +23,7 @@ #define DEVICE_KEY_SIZE 44 #define SIGNING_KEY_SIZE 44 #define ONETIME_KEY_SIZE 44 +#define MASTER_KEY_SIZE 44 #define KEY_SHARE_EVENT_LEN 1024 @@ -49,7 +50,7 @@ #define NUM_MEGOLM_SESSIONS 2 #define NUM_OLM_SESSIONS 2 -#define NUM_DEVICES 5 +#define NUM_DEVICES 10 // HTTP @@ -60,10 +61,6 @@ MatrixHttpInit( MatrixHttpConnection ** hc, const char * host); -// bool -// MatrixHttpConnect( -// MatrixHttpConnection * hc); - bool MatrixHttpDeinit( MatrixHttpConnection ** hc); @@ -152,6 +149,7 @@ MatrixOlmSessionUnpickle( void * pickled, int pickledLen, const void * key, int keyLen); +// create an olm sesseion from a type 0 message bool MatrixOlmSessionFrom( MatrixOlmSession * session, @@ -160,6 +158,7 @@ MatrixOlmSessionFrom( const char * deviceKey, const char * encrypted); +// create a new olm session from a claimed onetime key bool MatrixOlmSessionTo( MatrixOlmSession * session, @@ -227,18 +226,6 @@ MatrixMegolmOutSessionEncrypt( 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 @@ -254,15 +241,15 @@ typedef struct MatrixClient { MatrixDevice devices[NUM_DEVICES]; int numDevices; - - // char deviceKey[DEVICE_KEY_SIZE]; - // char signingKey[DEVICE_KEY_SIZE]; char userId[USER_ID_SIZE]; char accessToken[ACCESS_TOKEN_SIZE]; char deviceId[DEVICE_ID_SIZE]; char expireMs[EXPIRE_MS_SIZE]; char refreshToken[REFRESH_TOKEN_SIZE]; + char masterKey[MASTER_KEY_SIZE]; + + bool verified; MatrixHttpConnection * hc; } MatrixClient; @@ -271,16 +258,6 @@ bool MatrixClientInit( MatrixClient * client); -bool -MatrixClientSave( - MatrixClient * client, - const char * filename); - -bool -MatrixClientLoad( - MatrixClient * client, - const char * filename); - bool MatrixClientSetAccessToken( MatrixClient * client, @@ -306,7 +283,7 @@ MatrixClientUploadOnetimeKeys( MatrixClient * client); bool -MatrixClientUploadDeviceKey( +MatrixClientUploadDeviceKeys( MatrixClient * client); bool @@ -340,8 +317,8 @@ MatrixClientSendEventEncrypted( bool MatrixClientSync( MatrixClient * client, - char * outSync, int outSyncCap, - const char * nextBatch); + char * outSyncBuffer, int outSyncCap, + char * nextBatch, int nextBatchCap); bool MatrixClientGetRoomEvent( @@ -357,25 +334,21 @@ MatrixClientShareMegolmOutSession( const char * deviceId, MatrixMegolmOutSession * session); -bool -MatrixClientShareMegolmOutSessionTest( - MatrixClient * client, - const char * userId, - const char * deviceId, - MatrixMegolmOutSession * session); - +// try to lookup outgoing megolm session, return true if found bool MatrixClientGetMegolmOutSession( MatrixClient * client, const char * roomId, MatrixMegolmOutSession ** outSession); +// create a new outgoing megolm session and store it locally bool MatrixClientNewMegolmOutSession( MatrixClient * client, const char * roomId, MatrixMegolmOutSession ** outSession); +// try to lookup incoming megolm session, return true if found bool MatrixClientGetMegolmInSession( MatrixClient * client, @@ -383,6 +356,7 @@ MatrixClientGetMegolmInSession( const char * sessionId, int sessionIdLen, MatrixMegolmInSession ** outSession); +// create a new incoming megolm session and store it locally bool MatrixClientNewMegolmInSession( MatrixClient * client, @@ -390,7 +364,8 @@ MatrixClientNewMegolmInSession( const char * sessionId, const char * sessionKey, MatrixMegolmInSession ** outSession); - + +// send a m.room_key_request to the device identified by userId/devideId bool MatrixClientRequestMegolmInSession( MatrixClient * client, @@ -398,8 +373,9 @@ MatrixClientRequestMegolmInSession( const char * sessionId, const char * senderKey, const char * userId, - const char * deviceId); // TODO: remove deviceId (query all devices) + const char * deviceId); +// try to lookup olm session, return true if found bool MatrixClientGetOlmSession( MatrixClient * client, @@ -407,6 +383,7 @@ MatrixClientGetOlmSession( const char * deviceId, MatrixOlmSession ** outSession); +// create a new olm session from a type 0 message and store it locally bool MatrixClientNewOlmSessionIn( MatrixClient * client, @@ -414,7 +391,9 @@ MatrixClientNewOlmSessionIn( const char * deviceId, const char * encrypted, MatrixOlmSession ** outSession); - + +// create a new olm session with device userId/deviceId and store it locally +// this automatically claims the onetime key bool MatrixClientNewOlmSessionOut( MatrixClient * client, @@ -444,22 +423,33 @@ MatrixClientSendDummy( const char * userId, const char * deviceId); +// lookup device key locally and if not present get it from server bool MatrixClientRequestDeviceKey( MatrixClient * client, const char * deviceId, char * outDeviceKey, int outDeviceKeyCap); +// lookup signing key locally and if not present get it from server bool MatrixClientRequestSigningKey( MatrixClient * client, const char * deviceId, char * outSigningKey, int outSigningKeyCap); +// lookup the master key for this user and if not present get it from server +bool +MatrixClientRequestMasterKey( + MatrixClient * client, + char * outMasterKey, int outMasterKeyCap); + +// call keys/query and store retrieved information +// this is called by the other Request* functions bool MatrixClientRequestDeviceKeys( MatrixClient * client); +// delete this device on the server bool MatrixClientDeleteDevice( MatrixClient * client);