self_crypto 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/self_crypto/account.c +126 -120
- data/ext/self_crypto/extconf.rb +2 -4
- data/ext/self_crypto/omemo.c +40 -49
- data/ext/self_crypto/self_crypto.c +9 -40
- data/ext/self_crypto/session.c +71 -219
- data/ext/self_crypto/utility.c +73 -110
- data/lib/self_crypto/session.rb +0 -2
- data/lib/self_crypto/version.rb +1 -1
- data/lib/self_crypto.rb +0 -1
- data/test/spec/test_account.rb +0 -28
- metadata +8 -19
- data/ext/self_crypto/pk.c +0 -15
- data/ext/self_crypto/pk_decryption.c +0 -129
- data/ext/self_crypto/pk_encryption.c +0 -93
- data/ext/self_crypto/pk_signing.c +0 -102
- data/ext/self_crypto/sas.c +0 -190
- data/lib/self_crypto/sas.rb +0 -28
- data/lib/self_crypto/sas_data.rb +0 -71
- data/test/examples/test_bob_no_answer.rb +0 -62
- data/test/examples/test_exchange.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31cc22c6b9dd88e85087d810252d8c27ffe3519794f3bcc9508b518c45e169d8
|
4
|
+
data.tar.gz: fce33b4e5a82e3733a271cb7f7d6550f3689e93f0f80a1b4c8976f30f5115f7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4ba1661748742d3b5bdb3f563b71ca88ab646e1c05bfdf7578ff2943a672b592455a8ec039457069f2b7ac88b951344415a2349a20545b7a9683d8f13a92d2b
|
7
|
+
data.tar.gz: ab7e3453c2d122c5fb68eca9d9c5606c3184626765fed83baac4166e2d76fb0cfad15c9776e42513a034a04d9526d1f3020675fdb4c85aad4d624d6b85935254
|
data/ext/self_crypto/account.c
CHANGED
@@ -1,130 +1,154 @@
|
|
1
|
-
#include "
|
2
|
-
#include "self_olm/olm.h"
|
1
|
+
#include "self_omemo.h"
|
3
2
|
#include "self_crypto.h"
|
4
3
|
|
5
|
-
static VALUE last_error(VALUE self)
|
6
|
-
|
7
|
-
OlmAccount *this;
|
4
|
+
static VALUE last_error(VALUE self) {
|
5
|
+
OlmAccount * this;
|
8
6
|
Data_Get_Struct(self, OlmAccount, this);
|
9
7
|
|
10
|
-
return rb_funcall(rb_eval_string("SelfCrypto::OlmError"), rb_intern("from_string"), 1, rb_str_new2(
|
8
|
+
return rb_funcall(rb_eval_string("SelfCrypto::OlmError"), rb_intern("from_string"), 1, rb_str_new2(self_olm_account_last_error(this)));
|
11
9
|
}
|
12
10
|
|
13
|
-
static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
14
|
-
{
|
11
|
+
static VALUE initialize(int argc, VALUE * argv, VALUE self) {
|
15
12
|
VALUE pickle, password, seed, opts;
|
16
13
|
size_t size;
|
17
|
-
OlmAccount *this;
|
14
|
+
OlmAccount * this;
|
15
|
+
|
18
16
|
Data_Get_Struct(self, OlmAccount, this);
|
19
17
|
|
20
|
-
(void)rb_scan_args(argc, argv, "0:", &opts);
|
18
|
+
(void) rb_scan_args(argc, argv, "0:", & opts);
|
21
19
|
|
22
|
-
opts = (opts == Qnil) ? rb_hash_new(): opts;
|
20
|
+
opts = (opts == Qnil) ? rb_hash_new() : opts;
|
23
21
|
|
24
22
|
pickle = rb_hash_aref(opts, ID2SYM(rb_intern("pickle")));
|
25
23
|
password = rb_hash_aref(opts, ID2SYM(rb_intern("password")));
|
26
24
|
seed = rb_hash_aref(opts, ID2SYM(rb_intern("seed")));
|
27
25
|
|
28
|
-
if(pickle != Qnil){
|
29
|
-
|
30
|
-
if(rb_obj_is_kind_of(pickle, rb_cString) != Qtrue){
|
31
|
-
|
26
|
+
if (pickle != Qnil) {
|
27
|
+
if (rb_obj_is_kind_of(pickle, rb_cString) != Qtrue) {
|
32
28
|
rb_raise(rb_eTypeError, "pickle must be kind of String");
|
33
29
|
}
|
34
30
|
}
|
35
31
|
|
36
|
-
if(password != Qnil){
|
37
|
-
|
38
|
-
if(rb_obj_is_kind_of(password, rb_cString) != Qtrue){
|
39
|
-
|
32
|
+
if (password != Qnil) {
|
33
|
+
if (rb_obj_is_kind_of(password, rb_cString) != Qtrue) {
|
40
34
|
rb_raise(rb_eTypeError, "password must be kind of String");
|
41
35
|
}
|
42
|
-
}
|
43
|
-
else{
|
44
|
-
|
36
|
+
} else {
|
45
37
|
password = rb_str_new2("");
|
46
38
|
}
|
47
39
|
|
48
|
-
if(pickle != Qnil){
|
49
|
-
if(
|
50
|
-
raise_olm_error(
|
40
|
+
if (pickle != Qnil) {
|
41
|
+
if (self_olm_unpickle_account(this, RSTRING_PTR(password), RSTRING_LEN(password), RSTRING_PTR(dup_string(pickle)), RSTRING_LEN(pickle)) == -1) {
|
42
|
+
raise_olm_error(self_olm_account_last_error(this));
|
43
|
+
}
|
44
|
+
} else if (seed != Qnil) {
|
45
|
+
uint8_t *ed25519_pk = malloc_or_raise(self_crypto_sign_publickeybytes());
|
46
|
+
uint8_t *ed25519_sk = malloc_or_raise(self_crypto_sign_secretkeybytes());
|
47
|
+
uint8_t *curve25519_pk = malloc_or_raise(self_crypto_sign_publickeybytes()); // equivalent to crypto_scalarmult_curve25519_BYTES
|
48
|
+
uint8_t *curve25519_sk = malloc_or_raise(self_crypto_sign_publickeybytes()); // equivalent to crypto_scalarmult_curve25519_BYTES
|
49
|
+
size_t status = self_crypto_sign_seed_keypair(
|
50
|
+
ed25519_pk,
|
51
|
+
ed25519_sk,
|
52
|
+
RSTRING_PTR(seed)
|
53
|
+
);
|
54
|
+
|
55
|
+
if (status != 0) {
|
56
|
+
raise_olm_error("could not generate key from seed");
|
51
57
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
58
|
+
|
59
|
+
status = self_crypto_sign_ed25519_pk_to_curve25519(
|
60
|
+
curve25519_pk,
|
61
|
+
ed25519_pk
|
62
|
+
);
|
63
|
+
|
64
|
+
if (status != 0) {
|
65
|
+
raise_olm_error("could not convert ed25519 public key to curve25519");
|
66
|
+
}
|
67
|
+
|
68
|
+
status = self_crypto_sign_ed25519_sk_to_curve25519(
|
69
|
+
curve25519_sk,
|
70
|
+
ed25519_sk
|
71
|
+
);
|
72
|
+
|
73
|
+
if (status != 0) {
|
74
|
+
raise_olm_error("could not convert ed25519 secret key to curve25519");
|
75
|
+
}
|
76
|
+
|
77
|
+
status = self_olm_import_account(
|
78
|
+
this,
|
79
|
+
ed25519_sk,
|
80
|
+
ed25519_pk,
|
81
|
+
curve25519_sk,
|
82
|
+
curve25519_pk
|
83
|
+
);
|
84
|
+
|
85
|
+
if (status == -1) {
|
86
|
+
raise_olm_error(self_olm_account_last_error(this));
|
55
87
|
}
|
56
88
|
} else {
|
57
|
-
size =
|
89
|
+
size = self_olm_create_account_random_length(this);
|
58
90
|
|
59
|
-
if(
|
60
|
-
raise_olm_error(
|
91
|
+
if (self_olm_create_account(this, RSTRING_PTR(get_random(size)), size) == -1) {
|
92
|
+
raise_olm_error(self_olm_account_last_error(this));
|
61
93
|
}
|
62
94
|
}
|
63
95
|
|
64
96
|
return self;
|
65
97
|
}
|
66
98
|
|
67
|
-
static VALUE identity_keys(VALUE self)
|
68
|
-
|
69
|
-
OlmAccount *this;
|
99
|
+
static VALUE identity_keys(VALUE self) {
|
100
|
+
OlmAccount * this;
|
70
101
|
size_t size;
|
71
102
|
Data_Get_Struct(self, OlmAccount, this);
|
72
103
|
|
73
|
-
size =
|
104
|
+
size = self_olm_account_identity_keys_length(this);
|
74
105
|
uint8_t buf[size];
|
75
106
|
|
76
|
-
if(
|
77
|
-
|
78
|
-
raise_olm_error(olm_account_last_error(this));
|
107
|
+
if (self_olm_account_identity_keys(this, buf, size) != size) {
|
108
|
+
raise_olm_error(self_olm_account_last_error(this));
|
79
109
|
}
|
80
110
|
|
81
|
-
return rb_funcall(rb_eval_string("JSON"), rb_intern("parse"), 1, rb_str_new((char *)buf, size));
|
111
|
+
return rb_funcall(rb_eval_string("JSON"), rb_intern("parse"), 1, rb_str_new((char * ) buf, size));
|
82
112
|
}
|
83
113
|
|
84
|
-
static VALUE generate_one_time_keys(VALUE self, VALUE number)
|
85
|
-
{
|
114
|
+
static VALUE generate_one_time_keys(VALUE self, VALUE number) {
|
86
115
|
size_t size;
|
87
|
-
OlmAccount *this;
|
116
|
+
OlmAccount * this;
|
88
117
|
Data_Get_Struct(self, OlmAccount, this);
|
89
118
|
|
90
|
-
size =
|
119
|
+
size = self_olm_account_generate_one_time_keys_random_length(this, NUM2SIZET(number));
|
91
120
|
|
92
|
-
if(
|
93
|
-
|
94
|
-
raise_olm_error(olm_account_last_error(this));
|
121
|
+
if (self_olm_account_generate_one_time_keys(this, NUM2SIZET(number), RSTRING_PTR(get_random(size)), size) == -1) {
|
122
|
+
raise_olm_error(self_olm_account_last_error(this));
|
95
123
|
}
|
96
124
|
|
97
125
|
return self;
|
98
126
|
}
|
99
127
|
|
100
|
-
static VALUE one_time_keys_size(VALUE self)
|
101
|
-
|
102
|
-
OlmAccount *this;
|
128
|
+
static VALUE one_time_keys_size(VALUE self) {
|
129
|
+
OlmAccount * this;
|
103
130
|
Data_Get_Struct(self, OlmAccount, this);
|
104
131
|
|
105
|
-
return SIZET2NUM(
|
132
|
+
return SIZET2NUM(self_olm_account_one_time_keys_length(this));
|
106
133
|
}
|
107
134
|
|
108
|
-
static VALUE one_time_keys(VALUE self)
|
109
|
-
{
|
135
|
+
static VALUE one_time_keys(VALUE self) {
|
110
136
|
VALUE retval;
|
111
137
|
size_t size;
|
112
|
-
void *ptr;
|
113
|
-
OlmAccount *this;
|
138
|
+
void * ptr;
|
139
|
+
OlmAccount * this;
|
114
140
|
Data_Get_Struct(self, OlmAccount, this);
|
115
141
|
|
116
|
-
size =
|
142
|
+
size = self_olm_account_one_time_keys_length(this);
|
117
143
|
|
118
144
|
// add an additional byte to stop this from overflowing
|
119
|
-
if((ptr = malloc(size+1)) == NULL){
|
120
|
-
|
145
|
+
if ((ptr = malloc(size + 1)) == NULL) {
|
121
146
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
122
147
|
}
|
123
148
|
|
124
|
-
if(
|
125
|
-
|
149
|
+
if (self_olm_account_one_time_keys(this, ptr, size) != size) {
|
126
150
|
free(ptr);
|
127
|
-
raise_olm_error(
|
151
|
+
raise_olm_error(self_olm_account_last_error(this));
|
128
152
|
}
|
129
153
|
|
130
154
|
retval = rb_funcall(rb_eval_string("JSON"), rb_intern("parse"), 1, rb_str_new(ptr, size));
|
@@ -134,25 +158,22 @@ static VALUE one_time_keys(VALUE self)
|
|
134
158
|
return retval;
|
135
159
|
}
|
136
160
|
|
137
|
-
static VALUE sign(VALUE self, VALUE message)
|
138
|
-
{
|
161
|
+
static VALUE sign(VALUE self, VALUE message) {
|
139
162
|
VALUE retval;
|
140
163
|
size_t size;
|
141
|
-
void *ptr;
|
142
|
-
OlmAccount *this;
|
164
|
+
void * ptr;
|
165
|
+
OlmAccount * this;
|
143
166
|
Data_Get_Struct(self, OlmAccount, this);
|
144
167
|
|
145
|
-
size =
|
146
|
-
|
147
|
-
if((ptr = malloc(size)) == NULL){
|
168
|
+
size = self_olm_account_signature_length(this);
|
148
169
|
|
170
|
+
if ((ptr = malloc(size)) == NULL) {
|
149
171
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
150
172
|
}
|
151
173
|
|
152
|
-
if(
|
153
|
-
|
174
|
+
if (self_olm_account_sign(this, RSTRING_PTR(message), RSTRING_LEN(message), ptr, size) == -1) {
|
154
175
|
free(ptr);
|
155
|
-
raise_olm_error(
|
176
|
+
raise_olm_error(self_olm_account_last_error(this));
|
156
177
|
}
|
157
178
|
|
158
179
|
retval = rb_str_new(ptr, size);
|
@@ -162,77 +183,72 @@ static VALUE sign(VALUE self, VALUE message)
|
|
162
183
|
return retval;
|
163
184
|
}
|
164
185
|
|
165
|
-
static VALUE mark_keys_as_published(VALUE self)
|
166
|
-
|
167
|
-
OlmAccount *this;
|
186
|
+
static VALUE mark_keys_as_published(VALUE self) {
|
187
|
+
OlmAccount * this;
|
168
188
|
Data_Get_Struct(self, OlmAccount, this);
|
169
189
|
|
170
|
-
(void)
|
190
|
+
(void) self_olm_account_mark_keys_as_published(this);
|
171
191
|
|
172
192
|
return self;
|
173
193
|
}
|
174
194
|
|
175
|
-
static VALUE max_number_of_one_time_keys(VALUE self)
|
176
|
-
|
177
|
-
OlmAccount *this;
|
195
|
+
static VALUE max_number_of_one_time_keys(VALUE self) {
|
196
|
+
OlmAccount * this;
|
178
197
|
Data_Get_Struct(self, OlmAccount, this);
|
179
198
|
|
180
|
-
return SIZET2NUM(
|
199
|
+
return SIZET2NUM(self_olm_account_max_number_of_one_time_keys(this));
|
181
200
|
}
|
182
201
|
|
183
|
-
static VALUE remove_one_time_keys(VALUE self, VALUE session)
|
184
|
-
|
185
|
-
OlmAccount *this;
|
202
|
+
static VALUE remove_one_time_keys(VALUE self, VALUE session) {
|
203
|
+
OlmAccount * this;
|
186
204
|
Data_Get_Struct(self, OlmAccount, this);
|
187
205
|
|
188
|
-
OlmSession *s;
|
206
|
+
OlmSession * s;
|
189
207
|
Data_Get_Struct(session, OlmSession, s);
|
190
208
|
|
191
|
-
if(
|
192
|
-
|
193
|
-
raise_olm_error(olm_account_last_error(this));
|
209
|
+
if (self_olm_remove_one_time_keys(this, s) == -1) {
|
210
|
+
raise_olm_error(self_olm_account_last_error(this));
|
194
211
|
}
|
195
212
|
|
196
213
|
return self;
|
197
214
|
}
|
198
215
|
|
199
|
-
static VALUE outbound_session(VALUE self, VALUE identity_key, VALUE pre_key)
|
200
|
-
{
|
216
|
+
static VALUE outbound_session(VALUE self, VALUE identity_key, VALUE pre_key) {
|
201
217
|
return rb_funcall(rb_eval_string("SelfCrypto::OutboundSession"), rb_intern("new"), 3, self, identity_key, pre_key);
|
202
218
|
}
|
203
219
|
|
204
|
-
static VALUE inbound_session(int argc, VALUE *argv, VALUE self)
|
205
|
-
{
|
206
|
-
|
220
|
+
static VALUE inbound_session(int argc, VALUE * argv, VALUE self) {
|
221
|
+
VALUE args[] = {
|
222
|
+
self,
|
223
|
+
Qnil,
|
224
|
+
Qnil
|
225
|
+
};
|
207
226
|
|
208
|
-
(void)rb_scan_args(argc, argv, "11", &args[1], &args[2]);
|
227
|
+
(void) rb_scan_args(argc, argv, "11", & args[1], & args[2]);
|
209
228
|
|
210
|
-
return rb_class_new_instance(sizeof(args)/sizeof(*args), args, rb_eval_string("SelfCrypto::InboundSession"));
|
229
|
+
return rb_class_new_instance(sizeof(args) / sizeof( * args), args, rb_eval_string("SelfCrypto::InboundSession"));
|
211
230
|
}
|
212
231
|
|
213
|
-
static VALUE to_pickle(int argc, VALUE *argv, VALUE self)
|
214
|
-
{
|
232
|
+
static VALUE to_pickle(int argc, VALUE * argv, VALUE self) {
|
215
233
|
VALUE password, retval;
|
216
|
-
OlmAccount *this;
|
217
|
-
void *ptr;
|
234
|
+
OlmAccount * this;
|
235
|
+
void * ptr;
|
218
236
|
size_t size;
|
219
237
|
Data_Get_Struct(self, OlmAccount, this);
|
220
238
|
|
221
|
-
(void)rb_scan_args(argc, argv, "01", &password);
|
239
|
+
(void) rb_scan_args(argc, argv, "01", & password);
|
222
240
|
|
223
241
|
password = (password == Qnil) ? rb_str_new2("") : password;
|
224
242
|
|
225
|
-
size =
|
226
|
-
|
227
|
-
if((ptr = malloc(size)) == NULL){
|
243
|
+
size = self_olm_pickle_account_length(this);
|
228
244
|
|
245
|
+
if ((ptr = malloc(size)) == NULL) {
|
229
246
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
230
247
|
}
|
231
248
|
|
232
|
-
if(
|
233
|
-
|
249
|
+
if (self_olm_pickle_account(this, RSTRING_PTR(password), RSTRING_LEN(password), ptr, size) != size) {
|
234
250
|
free(ptr);
|
235
|
-
raise_olm_error(
|
251
|
+
raise_olm_error(self_olm_account_last_error(this));
|
236
252
|
}
|
237
253
|
|
238
254
|
retval = rb_str_new(ptr, size);
|
@@ -242,28 +258,18 @@ static VALUE to_pickle(int argc, VALUE *argv, VALUE self)
|
|
242
258
|
return retval;
|
243
259
|
}
|
244
260
|
|
245
|
-
static void _free(void *ptr)
|
246
|
-
{
|
247
|
-
olm_clear_account(ptr);
|
261
|
+
static void _free(void * ptr) {
|
248
262
|
free(ptr);
|
249
263
|
}
|
250
264
|
|
251
|
-
static VALUE _alloc(VALUE klass)
|
252
|
-
|
253
|
-
OlmAccount *
|
254
|
-
VALUE self;
|
255
|
-
|
256
|
-
self = Data_Wrap_Struct(klass, 0, _free, calloc(1, olm_account_size()));
|
257
|
-
|
258
|
-
Data_Get_Struct(self, OlmAccount, this);
|
265
|
+
static VALUE _alloc(VALUE klass) {
|
266
|
+
void *account_buf = calloc(1, self_olm_account_size());
|
267
|
+
OlmAccount *account = self_olm_account(account_buf);
|
259
268
|
|
260
|
-
(
|
261
|
-
|
262
|
-
return self;
|
269
|
+
return Data_Wrap_Struct(klass, 0, _free, account);
|
263
270
|
}
|
264
271
|
|
265
|
-
void account_init(void)
|
266
|
-
{
|
272
|
+
void account_init(void) {
|
267
273
|
VALUE cRubyOLM = rb_define_module("SelfCrypto");
|
268
274
|
VALUE cAccount = rb_define_class_under(cRubyOLM, "Account", rb_cObject);
|
269
275
|
|
@@ -282,4 +288,4 @@ void account_init(void)
|
|
282
288
|
rb_define_method(cAccount, "outbound_session", outbound_session, 2);
|
283
289
|
rb_define_method(cAccount, "inbound_session", inbound_session, -1);
|
284
290
|
rb_define_method(cAccount, "to_pickle", to_pickle, -1);
|
285
|
-
}
|
291
|
+
}
|
data/ext/self_crypto/extconf.rb
CHANGED
@@ -4,12 +4,10 @@ $CFLAGS = " -std=c99"
|
|
4
4
|
|
5
5
|
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
6
6
|
|
7
|
-
pkg_config('
|
7
|
+
pkg_config('stdc++')
|
8
8
|
pkg_config('self_omemo')
|
9
|
-
pkg_config("sodium")
|
10
9
|
|
11
|
-
abort "Missing
|
10
|
+
abort "Missing stdc++" unless have_library("stdc++")
|
12
11
|
abort "Missing omemo" unless have_library("self_omemo")
|
13
|
-
abort "Missing olm" unless have_library("self_olm")
|
14
12
|
|
15
13
|
create_makefile('self_crypto/self_crypto')
|
data/ext/self_crypto/omemo.c
CHANGED
@@ -1,79 +1,74 @@
|
|
1
1
|
// Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
2
|
|
3
|
-
#include "sodium.h"
|
4
|
-
#include "self_olm/olm.h"
|
5
3
|
#include "self_omemo.h"
|
6
4
|
#include "self_crypto.h"
|
7
5
|
|
8
|
-
static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
9
|
-
{
|
6
|
+
static VALUE initialize(int argc, VALUE * argv, VALUE self) {
|
10
7
|
VALUE identity;
|
11
|
-
GroupSession *this;
|
8
|
+
GroupSession * this;
|
12
9
|
|
13
10
|
Data_Get_Struct(self, GroupSession, this);
|
14
11
|
|
15
|
-
(void)rb_scan_args(argc, argv, "1", &identity);
|
12
|
+
(void) rb_scan_args(argc, argv, "1", & identity);
|
16
13
|
|
17
|
-
if(identity != Qnil){
|
18
|
-
if(rb_obj_is_kind_of(identity, rb_cString) != Qtrue){
|
14
|
+
if (identity != Qnil) {
|
15
|
+
if (rb_obj_is_kind_of(identity, rb_cString) != Qtrue) {
|
19
16
|
rb_raise(rb_eTypeError, "identity must be kind of String");
|
20
17
|
}
|
21
18
|
}
|
22
19
|
|
23
|
-
|
20
|
+
self_omemo_set_identity(this, RSTRING_PTR(identity));
|
24
21
|
|
25
22
|
return self;
|
26
23
|
}
|
27
24
|
|
28
|
-
static VALUE add_participant(VALUE self, VALUE identity, VALUE session)
|
29
|
-
|
30
|
-
|
31
|
-
OlmSession *s;
|
25
|
+
static VALUE add_participant(VALUE self, VALUE identity, VALUE session) {
|
26
|
+
GroupSession * this;
|
27
|
+
OlmSession * s;
|
32
28
|
|
33
29
|
Data_Get_Struct(self, GroupSession, this);
|
34
30
|
Data_Get_Struct(session, OlmSession, s);
|
35
31
|
|
36
|
-
if(rb_obj_is_kind_of(identity, rb_eval_string("String")) != Qtrue){
|
32
|
+
if (rb_obj_is_kind_of(identity, rb_eval_string("String")) != Qtrue) {
|
37
33
|
rb_raise(rb_eTypeError, "identity must be kind of String");
|
38
34
|
}
|
39
35
|
|
40
|
-
if(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
if (
|
37
|
+
rb_obj_is_instance_of(session, rb_eval_string("SelfCrypto::Session")) != Qtrue &&
|
38
|
+
rb_obj_is_instance_of(session, rb_eval_string("SelfCrypto::InboundSession")) != Qtrue &&
|
39
|
+
rb_obj_is_instance_of(session, rb_eval_string("SelfCrypto::OutboundSession")) != Qtrue
|
40
|
+
) {
|
45
41
|
rb_raise(rb_eTypeError, "session must be an instance of SelfCrypto::Session, SelfCrypto::InboundSession or SelfCrypto::OutboundSession");
|
46
42
|
}
|
47
43
|
|
48
|
-
|
44
|
+
self_omemo_add_group_participant(this, RSTRING_PTR(identity), s);
|
49
45
|
|
50
46
|
return identity;
|
51
47
|
}
|
52
48
|
|
53
|
-
static VALUE group_encrypt(VALUE self, VALUE plaintext)
|
54
|
-
|
55
|
-
GroupSession *this;
|
49
|
+
static VALUE group_encrypt(VALUE self, VALUE plaintext) {
|
50
|
+
GroupSession * this;
|
56
51
|
VALUE ciphertext;
|
57
|
-
void *ptr;
|
52
|
+
void * ptr;
|
58
53
|
size_t ciphertext_sz;
|
59
54
|
|
60
55
|
Data_Get_Struct(self, GroupSession, this);
|
61
56
|
|
62
|
-
if(rb_obj_is_kind_of(plaintext, rb_eval_string("String")) != Qtrue){
|
57
|
+
if (rb_obj_is_kind_of(plaintext, rb_eval_string("String")) != Qtrue) {
|
63
58
|
rb_raise(rb_eTypeError, "plaintext must be kind of String");
|
64
59
|
}
|
65
60
|
|
66
|
-
ciphertext_sz =
|
61
|
+
ciphertext_sz = self_omemo_encrypted_size(this, RSTRING_LEN(plaintext));
|
67
62
|
|
68
63
|
if (ciphertext_sz == 0) {
|
69
64
|
rb_raise(rb_eTypeError, "could not get size of encrypted message");
|
70
65
|
}
|
71
66
|
|
72
|
-
if((ptr = malloc(ciphertext_sz)) == NULL){
|
67
|
+
if ((ptr = malloc(ciphertext_sz)) == NULL) {
|
73
68
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
74
69
|
}
|
75
70
|
|
76
|
-
ciphertext_sz =
|
71
|
+
ciphertext_sz = self_omemo_encrypt(
|
77
72
|
this,
|
78
73
|
RSTRING_PTR(plaintext),
|
79
74
|
RSTRING_LEN(plaintext),
|
@@ -81,7 +76,7 @@ static VALUE group_encrypt(VALUE self, VALUE plaintext)
|
|
81
76
|
ciphertext_sz
|
82
77
|
);
|
83
78
|
|
84
|
-
if(ciphertext_sz == 0) {
|
79
|
+
if (ciphertext_sz == 0) {
|
85
80
|
free(ptr);
|
86
81
|
rb_raise(rb_eTypeError, "failed to encrypt");
|
87
82
|
}
|
@@ -93,34 +88,33 @@ static VALUE group_encrypt(VALUE self, VALUE plaintext)
|
|
93
88
|
return ciphertext;
|
94
89
|
}
|
95
90
|
|
96
|
-
static VALUE group_decrypt(VALUE self, VALUE sender, VALUE ciphertext)
|
97
|
-
|
98
|
-
GroupSession *this;
|
91
|
+
static VALUE group_decrypt(VALUE self, VALUE sender, VALUE ciphertext) {
|
92
|
+
GroupSession * this;
|
99
93
|
VALUE plaintext;
|
100
|
-
void *ptr;
|
94
|
+
void * ptr;
|
101
95
|
size_t plaintext_sz;
|
102
96
|
|
103
97
|
Data_Get_Struct(self, GroupSession, this);
|
104
98
|
|
105
|
-
if(rb_obj_is_kind_of(sender, rb_eval_string("String")) != Qtrue){
|
99
|
+
if (rb_obj_is_kind_of(sender, rb_eval_string("String")) != Qtrue) {
|
106
100
|
rb_raise(rb_eTypeError, "sender must be kind of String");
|
107
101
|
}
|
108
102
|
|
109
|
-
if(rb_obj_is_kind_of(ciphertext, rb_eval_string("String")) != Qtrue){
|
103
|
+
if (rb_obj_is_kind_of(ciphertext, rb_eval_string("String")) != Qtrue) {
|
110
104
|
rb_raise(rb_eTypeError, "ciphertext must be kind of String");
|
111
105
|
}
|
112
106
|
|
113
|
-
plaintext_sz =
|
107
|
+
plaintext_sz = self_omemo_decrypted_size(this, RSTRING_PTR(ciphertext), RSTRING_LEN(ciphertext));
|
114
108
|
|
115
109
|
if (plaintext_sz == 0) {
|
116
110
|
rb_raise(rb_eTypeError, "could not get size of decrypted message");
|
117
111
|
}
|
118
112
|
|
119
|
-
if((ptr = malloc(plaintext_sz)) == NULL){
|
113
|
+
if ((ptr = malloc(plaintext_sz)) == NULL) {
|
120
114
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
121
115
|
}
|
122
116
|
|
123
|
-
plaintext_sz =
|
117
|
+
plaintext_sz = self_omemo_decrypt(
|
124
118
|
this,
|
125
119
|
RSTRING_PTR(sender),
|
126
120
|
ptr,
|
@@ -129,7 +123,7 @@ static VALUE group_decrypt(VALUE self, VALUE sender, VALUE ciphertext)
|
|
129
123
|
RSTRING_LEN(ciphertext)
|
130
124
|
);
|
131
125
|
|
132
|
-
if(plaintext_sz == 0) {
|
126
|
+
if (plaintext_sz == 0) {
|
133
127
|
free(ptr);
|
134
128
|
rb_raise(rb_eTypeError, "failed to decrypt");
|
135
129
|
}
|
@@ -141,25 +135,22 @@ static VALUE group_decrypt(VALUE self, VALUE sender, VALUE ciphertext)
|
|
141
135
|
return plaintext;
|
142
136
|
}
|
143
137
|
|
144
|
-
static void _free(void *ptr)
|
145
|
-
|
146
|
-
omemo_destroy_group_session(ptr);
|
138
|
+
static void _free(void * ptr) {
|
139
|
+
self_omemo_destroy_group_session(ptr);
|
147
140
|
}
|
148
141
|
|
149
|
-
static VALUE _alloc(VALUE klass)
|
150
|
-
|
151
|
-
GroupSession *this;
|
142
|
+
static VALUE _alloc(VALUE klass) {
|
143
|
+
GroupSession * this;
|
152
144
|
VALUE self;
|
153
145
|
|
154
|
-
self = Data_Wrap_Struct(klass, 0, _free,
|
146
|
+
self = Data_Wrap_Struct(klass, 0, _free, self_omemo_create_group_session());
|
155
147
|
|
156
148
|
Data_Get_Struct(self, GroupSession, this);
|
157
149
|
|
158
150
|
return self;
|
159
151
|
}
|
160
152
|
|
161
|
-
void group_session_init()
|
162
|
-
{
|
153
|
+
void group_session_init() {
|
163
154
|
VALUE cRubyOLM = rb_define_module("SelfCrypto");
|
164
155
|
VALUE cGroupSession = rb_define_class_under(cRubyOLM, "GroupSession", rb_cObject);
|
165
156
|
|
@@ -169,4 +160,4 @@ void group_session_init()
|
|
169
160
|
rb_define_method(cGroupSession, "add_participant", add_participant, 2);
|
170
161
|
rb_define_method(cGroupSession, "encrypt", group_encrypt, 1);
|
171
162
|
rb_define_method(cGroupSession, "decrypt", group_decrypt, 2);
|
172
|
-
}
|
163
|
+
}
|