\r
strcpy(client->server, server);\r
\r
+ // init olm account\r
+ client->olmAccount = olm_account(client->olmAccountMemory);\r
+\r
+ static uint8_t random[OLM_ACCOUNT_RANDOM_SIZE];\r
+ Randomize(random, OLM_ACCOUNT_RANDOM_SIZE);\r
+\r
+ size_t res;\r
+ res = olm_create_account(\r
+ client->olmAccount,\r
+ random,\r
+ OLM_ACCOUNT_RANDOM_SIZE);\r
+\r
+ // set device key\r
+ static char deviceKeysJson[OLM_IDENTITY_KEYS_JSON_SIZE];\r
+ res =\r
+ olm_account_identity_keys(\r
+ client->olmAccount,\r
+ deviceKeysJson,\r
+ OLM_IDENTITY_KEYS_JSON_SIZE);\r
+\r
+ mjson_get_string(deviceKeysJson, res,\r
+ "$.curve25519",\r
+ client->deviceKey, DEVICE_KEY_SIZE);\r
+ mjson_get_string(deviceKeysJson, res,\r
+ "$.ed25519",\r
+ client->signingKey, SIGNING_KEY_SIZE);\r
+\r
return true;\r
}\r
\r
{\r
int accessTokenLen = strlen(accessToken);\r
\r
- if (accessTokenLen < ACCESS_TOKEN_SIZE - 1)\r
+ if (accessTokenLen > ACCESS_TOKEN_SIZE - 1)\r
return false;\r
\r
for (int i = 0; i < accessTokenLen; i++)\r
return true;\r
}\r
\r
+bool\r
+MatrixClientSetDeviceId(\r
+ MatrixClient * client,\r
+ const char * deviceId)\r
+{\r
+ int deviceIdLen = strlen(deviceId);\r
+\r
+ if (deviceIdLen > DEVICE_ID_SIZE - 1)\r
+ return false;\r
+\r
+ for (int i = 0; i < deviceIdLen; i++)\r
+ client->deviceId[i] = deviceId[i];\r
+\r
+ return true;\r
+}\r
+\r
// https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3login\r
bool\r
MatrixClientLoginPassword(\r
#define REFRESH_TOKEN_SIZE 20\r
#define MAX_URL_LEN 128\r
\r
-#define DEVICE_KEY_SIZE 20\r
+#define OLM_IDENTITY_KEYS_JSON_SIZE 128\r
+#define DEVICE_KEY_SIZE 44\r
+#define SIGNING_KEY_SIZE 44\r
\r
#define KEY_SHARE_EVENT_LEN 1024\r
\r
+#define OLM_ACCOUNT_MEMORY_SIZE 7528\r
+#define OLM_ACCOUNT_RANDOM_SIZE 32+32\r
+\r
#define OLM_SESSION_MEMORY_SIZE 3352\r
#define OLM_ENCRYPT_RANDOM_SIZE 32\r
\r
\r
typedef struct MatrixClient {\r
OlmAccount * olmAccount;\r
- OlmSession * olmSession;\r
+ char olmAccountMemory[OLM_ACCOUNT_MEMORY_SIZE];\r
\r
MatrixMegolmInSession megolmInSessions[NUM_MEGOLM_SESSIONS];\r
int numMegolmInSessions;\r
int numDevices;\r
\r
char deviceKey[DEVICE_KEY_SIZE];\r
+ char signingKey[DEVICE_KEY_SIZE];\r
\r
char userId[USER_ID_SIZE];\r
char server[SERVER_SIZE];\r
MatrixClient * client,\r
const char * accessToken);\r
\r
+bool\r
+MatrixClientSetDeviceId(\r
+ MatrixClient * client,\r
+ const char * deviceId);\r
+\r
bool\r
MatrixClientLoginPassword(\r
MatrixClient * client,\r