#define LOGIN_RESPONSE_SIZE 1024\r
#define LOGIN_URL "/_matrix/client/v3/login"\r
\r
-#define ENCRYPTED_REQUEST_SIZE 512\r
+#define ENCRYPTED_REQUEST_SIZE (1024*5)\r
#define ENCRYPTED_EVENT_SIZE 1024\r
#define ROOMEVENT_REQUEST_SIZE 256\r
#define ROOMEVENT_RESPONSE_SIZE 1024\r
uint8_t * random,\r
int randomLen)\r
{\r
- static bool first = false;\r
+ static bool first = true;\r
if (first) { srand(time(0)); first = false; }\r
\r
for (int i = 0; i < randomLen; i++)\r
\r
// TODO: in/outbound sessions\r
bool\r
-MatrixOlmSessionFrom(\r
+MatrixOlmSessionTo(\r
MatrixOlmSession * session,\r
OlmAccount * olmAccount,\r
const char * deviceId,\r
static uint8_t random[OLM_OUTBOUND_SESSION_RANDOM_SIZE];\r
Randomize(random, OLM_OUTBOUND_SESSION_RANDOM_SIZE);\r
\r
- olm_create_outbound_session(session->session,\r
- olmAccount,\r
- deviceKey, strlen(deviceKey),\r
- deviceOnetimeKey, strlen(deviceOnetimeKey),\r
- random, OLM_OUTBOUND_SESSION_RANDOM_SIZE);\r
+ size_t res =\r
+ olm_create_outbound_session(session->session,\r
+ olmAccount,\r
+ deviceKey, strlen(deviceKey),\r
+ deviceOnetimeKey, strlen(deviceOnetimeKey),\r
+ random, OLM_OUTBOUND_SESSION_RANDOM_SIZE);\r
+ \r
+ if (res == olm_error()) {\r
+ printf("error olm: %s\n", olm_account_last_error(olmAccount));\r
+ }\r
\r
return session->session != NULL;\r
}\r
\r
mjson_get_string(keyObject + voff, vlen,\r
"$.key", outOnetimeKey, outOnetimeKeyCap);\r
-\r
- printf("onetime key: %s\n", outOnetimeKey);\r
\r
// TODO: verify signature\r
\r
sprintf(encryptedEventBuffer,\r
"{"\r
"\"algorithm\":\"m.megolm.v1.aes-sha2\","\r
- "\"sender_key\":\"%s\","\r
"\"ciphertext\":\"%s\","\r
- "\"session_id\":\"%s\","\r
- "\"device_id\":\"%s\""\r
+ "\"device_id\":\"%s\","\r
+ "\"sender_key\":\"%s\","\r
+ "\"session_id\":\"%s\""\r
"}",\r
- senderKey,\r
encryptedBuffer,\r
- sessionId,\r
- deviceId);\r
+ deviceId,\r
+ senderKey,\r
+ sessionId);\r
\r
// send\r
return MatrixClientSendEvent(client,\r
session->key\r
);\r
\r
- // get olm session\r
- MatrixOlmSession * olmSession;\r
- MatrixClientGetOlmSession(client, userId, deviceId, &olmSession);\r
+ // // get olm session\r
+ // MatrixOlmSession * olmSession;\r
+ // MatrixClientGetOlmSession(client, userId, deviceId, &olmSession);\r
\r
- // encrypt\r
- char encryptedBuffer[KEY_SHARE_EVENT_LEN];\r
- MatrixOlmSessionEncrypt(olmSession,\r
- eventBuffer,\r
- encryptedBuffer, KEY_SHARE_EVENT_LEN);\r
+ // // encrypt\r
+ // char encryptedBuffer[KEY_SHARE_EVENT_LEN];\r
+ // MatrixOlmSessionEncrypt(olmSession,\r
+ // eventBuffer,\r
+ // encryptedBuffer, KEY_SHARE_EVENT_LEN);\r
\r
// send\r
MatrixClientSendToDeviceEncrypted(client,\r
- client->userId,\r
+ userId,\r
deviceId,\r
- encryptedBuffer,\r
+ eventBuffer,\r
"m.room_key");\r
\r
return true;\r
deviceId,\r
onetimeKey, ONETIME_KEY_SIZE);\r
\r
- MatrixOlmSessionFrom(\r
+ MatrixOlmSessionTo(\r
&client->olmSessions[client->numOlmSessions],\r
client->olmAccount.account,\r
deviceId,\r
// create event json\r
char deviceKey[DEVICE_KEY_SIZE];\r
MatrixClientGetDeviceKey(client, deviceId, deviceKey, DEVICE_KEY_SIZE);\r
- const char * senderKey = client->deviceKey;\r
\r
static char eventBuffer[TODEVICE_EVENT_SIZE];\r
sprintf(eventBuffer,\r
static char encryptedEventBuffer[ENCRYPTED_EVENT_SIZE];\r
sprintf(encryptedEventBuffer,\r
"{"\r
- "\"algorithm\":\"m.megolm.v1.aes-sha2\","\r
- "\"sender_key\":\"%s\","\r
+ "\"algorithm\":\"m.olm.v1.curve25519-aes-sha2\","\r
"\"ciphertext\":{"\r
"\"%s\":{"\r
"\"body\":\"%s\","\r
- "\"type\":\"%d\""\r
+ "\"type\":%d"\r
"}"\r
- "}"\r
+ "},"\r
+ "\"device_id\":\"%s\","\r
+ "\"sender_key\":\"%s\""\r
"}",\r
- senderKey,\r
deviceKey,\r
encryptedBuffer,\r
- olmSession->type);\r
+ 0, //olmSession->type,\r
+ client->deviceId,\r
+ client->deviceKey);\r
\r
// send\r
return MatrixClientSendToDevice(\r
const char * deviceId,\r
char * outDeviceKey, int outDeviceKeyCap)\r
{\r
+ MatrixDevice * device;\r
+ \r
+ if (MatrixClientFindDevice(client, deviceId, &device))\r
+ {\r
+ strncpy(outDeviceKey, device->deviceKey, outDeviceKeyCap);\r
+ return true;\r
+ }\r
+\r
MatrixClientRequestDeviceKeys(client);\r
\r
- MatrixDevice * device;\r
if (MatrixClientFindDevice(client, deviceId, &device))\r
{\r
strncpy(outDeviceKey, device->deviceKey, outDeviceKeyCap);\r