X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/ad9d01050b7b6d592a83ce14eeef7068bd981028..9826729ea9eb492b0b25c52b934d9f1283bb70dd:/src/matrix.c?ds=inline diff --git a/src/matrix.c b/src/matrix.c index 28e7634..33988b4 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -157,6 +157,33 @@ MatrixClientInit( strcpy(client->server, server); + // init olm account + client->olmAccount = olm_account(client->olmAccountMemory); + + static uint8_t random[OLM_ACCOUNT_RANDOM_SIZE]; + Randomize(random, OLM_ACCOUNT_RANDOM_SIZE); + + size_t res; + res = olm_create_account( + client->olmAccount, + random, + OLM_ACCOUNT_RANDOM_SIZE); + + // set device key + static char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE]; + res = + olm_account_identity_keys( + client->olmAccount, + deviceKeysJson, + OLM_IDENTITY_KEYS_JSON_SIZE); + + mjson_get_string(deviceKeysJson, res, + "$.curve25519", + client->deviceKey, DEVICE_KEY_SIZE); + mjson_get_string(deviceKeysJson, res, + "$.ed25519", + client->signingKey, SIGNING_KEY_SIZE); + return true; } @@ -167,7 +194,7 @@ MatrixClientSetAccessToken( { int accessTokenLen = strlen(accessToken); - if (accessTokenLen < ACCESS_TOKEN_SIZE - 1) + if (accessTokenLen > ACCESS_TOKEN_SIZE - 1) return false; for (int i = 0; i < accessTokenLen; i++) @@ -176,6 +203,22 @@ MatrixClientSetAccessToken( return true; } +bool +MatrixClientSetDeviceId( + MatrixClient * client, + const char * deviceId) +{ + int deviceIdLen = strlen(deviceId); + + if (deviceIdLen > DEVICE_ID_SIZE - 1) + return false; + + for (int i = 0; i < deviceIdLen; i++) + client->deviceId[i] = deviceId[i]; + + return true; +} + // https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3login bool MatrixClientLoginPassword( @@ -294,7 +337,7 @@ MatrixClientSendEventEncrypted( "\"algorithm\":\"m.megolm.v1.aes-sha2\"," "\"sender_key\":\"%s\"," "\"ciphertext\":\"%s\"," - "\"session_id\":%s," + "\"session_id\":\"%s\"," "\"device_id\":\"%s\"" "}", senderKey,