olm_outbound_group_session.cpp 19.6 KB
Newer Older
1
2
/*
 * Copyright 2016 OpenMarket Ltd
ylecollen's avatar
ylecollen committed
3
 * Copyright 2016 Vector Creations Ltd
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "olm_outbound_group_session.h"

pedroGitt's avatar
pedroGitt committed
20
using namespace AndroidOlmSdk;
21
22
23
24
25
26
27
28

/**
 * Release the session allocation made by initializeOutboundGroupSessionMemory().<br>
 * This method MUST be called when java counter part account instance is done.
 *
 */
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
{
29
    LOGD("## releaseSessionJni(): OutBound group session IN");
30

31
    OlmOutboundGroupSession* sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
32

33
34
35
36
37
38
39
    if (!sessionPtr)
    {
        LOGE(" ## releaseSessionJni(): failure - invalid outbound group session instance");
    }
    else
    {
        LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
40

41
#ifdef ENABLE_JNI_LOG
42
43
        size_t retCode = olm_clear_outbound_group_session(sessionPtr);
        LOGD(" ## releaseSessionJni(): clear_outbound_group_session=%lu",static_cast<long unsigned int>(retCode));
44
#else
45
        olm_clear_outbound_group_session(sessionPtr);
46
#endif
47

48
49
50
51
        LOGD(" ## releaseSessionJni(): free IN");
        free(sessionPtr);
        LOGD(" ## releaseSessionJni(): free OUT");
    }
52
53
54
}

/**
ylecollen's avatar
ylecollen committed
55
56
57
58
59
 * Initialize a new outbound group session and return it to JAVA side.<br>
 * Since a C prt is returned as a jlong, special care will be taken
 * to make the cast (OlmOutboundGroupSession* => jlong) platform independent.
 * @return the initialized OlmOutboundGroupSession* instance or throw an exception
 **/
60
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz)
61
{
ylecollen's avatar
ylecollen committed
62
63
    const char* errorMessage = NULL;

64
    OlmOutboundGroupSession* sessionPtr = NULL;
65
66
    size_t sessionSize = 0;

67
    LOGD("## createNewSessionJni(): outbound group session IN");
68
    sessionSize = olm_outbound_group_session_size();
69

70
    if (0 == sessionSize)
71
    {
72
        LOGE(" ## createNewSessionJni(): failure - outbound group session size = 0");
ylecollen's avatar
ylecollen committed
73
        errorMessage = "outbound group session size = 0";
74
    }
ylecollen's avatar
ylecollen committed
75
    else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
76
    {
77
        LOGE(" ## createNewSessionJni(): failure - outbound group session OOM");
ylecollen's avatar
ylecollen committed
78
        errorMessage = "outbound group session OOM";
79
80
81
    }
    else
    {
ylecollen's avatar
ylecollen committed
82
83
84
        sessionPtr = olm_outbound_group_session(sessionPtr);
        LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",static_cast<long unsigned int>(sessionSize));

85
86
        // compute random buffer
        size_t randomLength = olm_init_outbound_group_session_random_length(sessionPtr);
87
88
        uint8_t *randomBuffPtr = NULL;

ylecollen's avatar
ylecollen committed
89
        LOGW(" ## createNewSessionJni(): randomLength=%lu",static_cast<long unsigned int>(randomLength));
90
91

        if ((0 != randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
92
        {
ylecollen's avatar
ylecollen committed
93
            LOGE(" ## createNewSessionJni(): failure - random buffer init");
94
            errorMessage = "random buffer init";
95
96
97
        }
        else
        {
98
            if (0 == randomLength)
99
            {
ylecollen's avatar
ylecollen committed
100
                LOGW(" ## createNewSessionJni(): random buffer is not required");
101
102
            }

103
            size_t sessionResult = olm_init_outbound_group_session(sessionPtr, randomBuffPtr, randomLength);
104
105

            if (sessionResult == olm_error()) {
106
                errorMessage = (const char *)olm_outbound_group_session_last_error(sessionPtr);
ylecollen's avatar
ylecollen committed
107
                LOGE(" ## createNewSessionJni(): failure - init outbound session creation  Msg=%s", errorMessage);
108
109
110
            }
            else
            {
ylecollen's avatar
ylecollen committed
111
                LOGD(" ## createNewSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
112
113
            }

114
115
            // clear the random buffer
            memset(randomBuffPtr, 0, randomLength);
116
117
            free(randomBuffPtr);
        }
118
    }
119

120
121
    if (errorMessage)
    {
ylecollen's avatar
ylecollen committed
122
123
124
125
126
127
        if (sessionPtr)
        {
            olm_clear_outbound_group_session(sessionPtr);
            free(sessionPtr);
        }

128
129
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }
ylecollen's avatar
ylecollen committed
130
131

    return (jlong)(intptr_t)sessionPtr;
132
133
134
}

/**
ylecollen's avatar
ylecollen committed
135
136
137
138
 * Return the session identifier.
 * An exception is thrown if the operation fails.
 * @return the session identifier
 */
139
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
140
141
142
{
    LOGD("## sessionIdentifierJni(): outbound group session IN");

143
    const char* errorMessage = NULL;
144
145
146
    OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
    jbyteArray returnValue = 0;
    
147
    if (!sessionPtr)
148
    {
149
        LOGE(" ## sessionIdentifierJni(): failure - invalid outbound group session instance");
150
        errorMessage = "invalid outbound group session instance";
151
152
153
    }
    else
    {
154
155
        // get the size to alloc
        size_t lengthSessionId = olm_outbound_group_session_id_length(sessionPtr);
pedroGitt's avatar
pedroGitt committed
156
        LOGD(" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
157

158
        uint8_t *sessionIdPtr =  (uint8_t*)malloc(lengthSessionId*sizeof(uint8_t));
159
160

        if (!sessionIdPtr)
161
        {
162
           LOGE(" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM");
163
           errorMessage = "outbound identifier allocation OOM";
164
165
166
        }
        else
        {
167
            size_t result = olm_outbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
168

169
170
            if (result == olm_error())
            {
171
172
                errorMessage = reinterpret_cast<const char*>(olm_outbound_group_session_last_error(sessionPtr));
                LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s", errorMessage);
173
174
175
            }
            else
            {
176
177
178
                returnValue = env->NewByteArray(result);
                env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);

ylecollen's avatar
ylecollen committed
179
                LOGD(" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId= %.*s",static_cast<long unsigned int>(result), static_cast<int>(result), reinterpret_cast<char*>(sessionIdPtr));
180
            }
181

182
183
184
185
            // free alloc
            free(sessionIdPtr);
        }
    }
186

187
188
189
190
191
    if (errorMessage)
    {
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }

192
    return returnValue;
193
194
195
}


196
/**
ylecollen's avatar
ylecollen committed
197
198
199
200
201
202
 * Get the current message index for this session.<br>
 * Each message is sent with an increasing index, this
 * method returns the index for the next message.
 * An exception is thrown if the operation fails.
 * @return current session index
 */
203
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz)
204
{
205
206
    OlmOutboundGroupSession *sessionPtr = NULL;
    jint indexRetValue = 0;
207

208
    LOGD("## messageIndexJni(): IN");
209

210
    if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
211
    {
212
        LOGE(" ## messageIndexJni(): failure - invalid outbound group session instance");
213
214
    }
    else
215
    {
216
        indexRetValue = static_cast<jint>(olm_outbound_group_session_message_index(sessionPtr));
217
    }
218

219
    LOGD(" ## messageIndexJni(): success - index=%d",indexRetValue);
220
221
222
223
224

    return indexRetValue;
}

/**
ylecollen's avatar
ylecollen committed
225
226
227
228
 * Return the session key.
 * An exception is thrown if the operation fails.
 * @return the session key
 */
229
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
230
231
{
    LOGD("## sessionKeyJni(): outbound group session IN");
232

233
    const char* errorMessage = NULL;
234
    OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
235
    jbyteArray returnValue = 0;
236

237
    if (!sessionPtr)
238
    {
239
        LOGE(" ## sessionKeyJni(): failure - invalid outbound group session instance");
240
        errorMessage = "invalid outbound group session instance";
241
242
243
    }
    else
    {
244
245
        // get the size to alloc
        size_t sessionKeyLength = olm_outbound_group_session_key_length(sessionPtr);
pedroGitt's avatar
pedroGitt committed
246
        LOGD(" ## sessionKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
247

248
        uint8_t *sessionKeyPtr = (uint8_t*)malloc(sessionKeyLength*sizeof(uint8_t));
249
250

        if (!sessionKeyPtr)
251
        {
252
           LOGE(" ## sessionKeyJni(): failure - session key allocation OOM");
253
           errorMessage = "session key allocation OOM";
254
255
256
        }
        else
        {
257
            size_t result = olm_outbound_group_session_key(sessionPtr, sessionKeyPtr, sessionKeyLength);
258

259
260
            if (result == olm_error())
            {
261
262
                errorMessage = (const char *)olm_outbound_group_session_last_error(sessionPtr);
                LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s", errorMessage);
263
264
265
            }
            else
            {
ylecollen's avatar
ylecollen committed
266
                LOGD(" ## sessionKeyJni(): success - outbound group session key result=%lu sessionKey=%.*s",static_cast<long unsigned int>(result), static_cast<int>(result), reinterpret_cast<char*>(sessionKeyPtr));
267
268
269

                returnValue = env->NewByteArray(result);
                env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionKeyPtr);
270
            }
271

272
273
            // free alloc
            free(sessionKeyPtr);
274
275
276
        }
    }

277
278
279
280
281
    if (errorMessage)
    {
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }

282
    return returnValue;
283
284
}

ylecollen's avatar
ylecollen committed
285
286
287
288
289
290
/**
 * Encrypt a bytes buffer messages.
 * An exception is thrown if the operation fails.
 * @param aClearMsgBuffer  the message to encode
 * @return the encoded message
 */
291
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer)
292
{
293
294
    LOGD("## encryptMessageJni(): IN");

295
    const char* errorMessage = NULL;
296
297
    jbyteArray encryptedMsgRet = 0;

298
    OlmOutboundGroupSession *sessionPtr = NULL;
299
    jbyte* clearMsgPtr = NULL;
300

301
    if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
302
    {
303
        LOGE(" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL");
304
        errorMessage = "invalid outbound group session ptr=NULL";
305
    }
306
    else if (!aClearMsgBuffer)
307
    {
308
        LOGE(" ## encryptMessageJni(): failure - invalid clear message");
309
        errorMessage = "invalid clear message";
310
    }
311
    else if (!(clearMsgPtr = env->GetByteArrayElements(aClearMsgBuffer, NULL)))
312
    {
313
        LOGE(" ## encryptMessageJni(): failure - clear message JNI allocation OOM");
314
        errorMessage = "clear message JNI allocation OOM";
315
    }
316
317
    else
    {
318
        // get clear message length
319
        size_t clearMsgLength = (size_t)env->GetArrayLength(aClearMsgBuffer);
pedroGitt's avatar
pedroGitt committed
320
        LOGD(" ## encryptMessageJni(): clearMsgLength=%lu",static_cast<long unsigned int>(clearMsgLength));
321

322
323
        // compute max encrypted length
        size_t encryptedMsgLength = olm_group_encrypt_message_length(sessionPtr,clearMsgLength);
324
        uint8_t *encryptedMsgPtr = (uint8_t*)malloc(encryptedMsgLength*sizeof(uint8_t));
325
326

        if (!encryptedMsgPtr)
327
        {
328
            LOGE(" ## encryptMessageJni(): failure - encryptedMsgPtr buffer OOM");
329
            errorMessage = "encryptedMsgPtr buffer OOM";
330
331
332
        }
        else
        {
pedroGitt's avatar
pedroGitt committed
333
            LOGD(" ## encryptMessageJni(): estimated encryptedMsgLength=%lu",static_cast<long unsigned int>(encryptedMsgLength));
334

335
            size_t encryptedLength = olm_group_encrypt(sessionPtr,
336
337
338
339
                                                       (uint8_t*)clearMsgPtr,
                                                       clearMsgLength,
                                                       encryptedMsgPtr,
                                                       encryptedMsgLength);
340
341


342
            if (encryptedLength == olm_error())
343
            {
344
345
                errorMessage = olm_outbound_group_session_last_error(sessionPtr);
                LOGE(" ## encryptMessageJni(): failure - olm_group_decrypt_max_plaintext_length Msg=%s", errorMessage);
346
347
348
            }
            else
            {
ylecollen's avatar
ylecollen committed
349
                LOGD(" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%.*s",static_cast<long unsigned int>(encryptedLength), static_cast<int>(encryptedLength), reinterpret_cast<char*>(encryptedMsgPtr));
350
351
352

                encryptedMsgRet = env->NewByteArray(encryptedLength);
                env->SetByteArrayRegion(encryptedMsgRet, 0 , encryptedLength, (jbyte*)encryptedMsgPtr);
353
            }
354
355
356

            free(encryptedMsgPtr);
         }
357
    }
358
359

    // free alloc
360
    if (clearMsgPtr)
361
    {
362
        env->ReleaseByteArrayElements(aClearMsgBuffer, clearMsgPtr, JNI_ABORT);
363
364
    }

365
366
367
368
369
    if (errorMessage)
    {
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }

370
    return encryptedMsgRet;
371
372
}

373
/**
ylecollen's avatar
ylecollen committed
374
375
376
377
378
 * Serialize and encrypt session instance into a base64 string.<br>
 * An exception is thrown if the operation fails.
 * @param aKey key used to encrypt the serialized session data
 * @return a base64 string if operation succeed, null otherwise
 **/
379
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
380
{
381
    const char* errorMessage = NULL;
382
    jbyteArray returnValue = 0;
383

384
    jbyte* keyPtr = NULL;
385
386
    OlmOutboundGroupSession* sessionPtr = NULL;

387
    LOGD("## outbound group session serializeJni(): IN");
388

389
    if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
390
    {
391
        LOGE(" ## serializeJni(): failure - invalid session ptr");
392
        errorMessage = "invalid session ptr";
393
    }
394
    else if (!aKeyBuffer)
395
    {
396
        LOGE(" ## serializeJni(): failure - invalid key");
397
        errorMessage = "invalid key";
398
    }
399
    else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
400
    {
401
        LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
402
        errorMessage = "keyPtr JNI allocation OOM";
403
404
405
406
    }
    else
    {
        size_t pickledLength = olm_pickle_outbound_group_session_length(sessionPtr);
407
        size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
408
        LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
409

410
        void *pickledPtr = malloc(pickledLength*sizeof(uint8_t));
411
412

        if(!pickledPtr)
413
        {
414
            LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
415
            errorMessage = "pickledPtr buffer OOM";
416
417
418
419
420
421
422
423
        }
        else
        {
            size_t result = olm_pickle_outbound_group_session(sessionPtr,
                                                             (void const *)keyPtr,
                                                              keyLength,
                                                              (void*)pickledPtr,
                                                              pickledLength);
424
            if (result == olm_error())
425
            {
426
427
                errorMessage = olm_outbound_group_session_last_error(sessionPtr);
                LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s", errorMessage);
428
429
430
            }
            else
            {
ylecollen's avatar
ylecollen committed
431
                LOGD(" ## serializeJni(): success - result=%lu pickled=%.*s", static_cast<long unsigned int>(result), static_cast<int>(result), static_cast<char*>(pickledPtr));
432
433
434

                returnValue = env->NewByteArray(pickledLength);
                env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr);
435
436
437
            }
        }

438
        free(pickledPtr);
439
440
    }

441
442
    // free alloc
    if (keyPtr)
443
    {
444
        env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
445
446
    }

447
448
449
450
451
    if (errorMessage)
    {
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }

452
    return returnValue;
453
454
}

ylecollen's avatar
ylecollen committed
455
456
457
458
459
460
461
462
/**
 * Allocate a new session and initialize it with the serialisation data.<br>
 * An exception is thrown if the operation fails.
 * @param aSerializedData the session serialisation buffer
 * @param aKey the key used to encrypt the serialized account data
 * @return the deserialized session
 **/
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
463
{
ylecollen's avatar
ylecollen committed
464
465
    const char* errorMessage = NULL;
    size_t sessionSize = olm_outbound_group_session_size();
466
    OlmOutboundGroupSession* sessionPtr = NULL;
ylecollen's avatar
ylecollen committed
467

468
469
    jbyte* keyPtr = NULL;
    jbyte* pickledPtr = NULL;
470

471
    LOGD("## deserializeJni(): IN");
472

ylecollen's avatar
ylecollen committed
473
474
475
476
477
478
    if (!sessionSize)
    {
        LOGE(" ## deserializeJni(): failure - outbound group session size = 0");
        errorMessage = "outbound group session size = 0";
    }
    else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
479
    {
480
        LOGE(" ## deserializeJni(): failure - session failure OOM");
ylecollen's avatar
ylecollen committed
481
        errorMessage = "session failure OOM";
482
    }
483
    else if (!aKeyBuffer)
484
    {
485
        LOGE(" ## deserializeJni(): failure - invalid key");
ylecollen's avatar
ylecollen committed
486
        errorMessage = "invalid key";
487
    }
488
    else if (!aSerializedDataBuffer)
489
    {
490
        LOGE(" ## deserializeJni(): failure - serialized data");
ylecollen's avatar
ylecollen committed
491
        errorMessage = "invalid serialized data";
492
    }
493
    else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
494
    {
495
        LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
ylecollen's avatar
ylecollen committed
496
        errorMessage = "keyPtr JNI allocation OOM";
497
    }
498
    else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
499
    {
500
        LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
ylecollen's avatar
ylecollen committed
501
        errorMessage = "pickledPtr JNI allocation OOM";
502
503
504
    }
    else
    {
ylecollen's avatar
ylecollen committed
505
        sessionPtr = olm_outbound_group_session(sessionPtr);
506
507
        size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
        size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
508
        LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
ylecollen's avatar
ylecollen committed
509
        LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int>(pickledLength), (char const *)pickledPtr);
510
511
512
513
514
515

        size_t result = olm_unpickle_outbound_group_session(sessionPtr,
                                                            (void const *)keyPtr,
                                                            keyLength,
                                                            (void*)pickledPtr,
                                                            pickledLength);
516
        if (result == olm_error())
517
        {
ylecollen's avatar
ylecollen committed
518
519
            errorMessage = olm_outbound_group_session_last_error(sessionPtr);
            LOGE(" ## deserializeJni(): failure - olm_unpickle_outbound_group_session() Msg=%s", errorMessage);
520
521
522
        }
        else
        {
523
            LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
524
525
526
527
        }
    }

    // free alloc
528
    if (keyPtr)
529
    {
530
        env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
531
532
    }

533
    if (pickledPtr)
534
    {
535
        env->ReleaseByteArrayElements(aSerializedDataBuffer, pickledPtr, JNI_ABORT);
536
537
    }

ylecollen's avatar
ylecollen committed
538
539
540
541
542
543
544
545
546
547
548
    if (errorMessage)
    {
        if (sessionPtr)
        {
            olm_clear_outbound_group_session(sessionPtr);
            free(sessionPtr);
        }
        env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
    }

    return (jlong)(intptr_t)sessionPtr;
549
}
550