self_crypto 0.0.7 → 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 +42 -49
- data/ext/self_crypto/self_crypto.c +9 -40
- data/ext/self_crypto/session.c +71 -219
- data/ext/self_crypto/utility.c +152 -73
- data/lib/self_crypto/group_message.rb +2 -0
- data/lib/self_crypto/group_session.rb +2 -0
- data/lib/self_crypto/session.rb +0 -2
- data/lib/self_crypto/utility.rb +2 -0
- data/lib/self_crypto/version.rb +3 -1
- data/lib/self_crypto.rb +2 -1
- data/test/spec/test_account.rb +0 -28
- data/test/spec/test_util.rb +12 -0
- metadata +9 -20
- 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
data/ext/self_crypto/utility.c
CHANGED
|
@@ -1,89 +1,199 @@
|
|
|
1
|
-
#include "
|
|
1
|
+
#include "self_omemo.h"
|
|
2
2
|
#include "self_crypto.h"
|
|
3
|
-
#include "sodium.h"
|
|
4
3
|
|
|
5
|
-
static VALUE
|
|
6
|
-
|
|
7
|
-
OlmUtility *this;
|
|
8
|
-
Data_Get_Struct(self, OlmUtility, this);
|
|
4
|
+
static VALUE random_bytes(VALUE self, VALUE size) {
|
|
5
|
+
void * nonce;
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
if (size == Qnil) {
|
|
8
|
+
rb_raise(rb_eStandardError, "must specify a size");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if ((nonce = malloc(NUM2SIZET(size))) == NULL) {
|
|
12
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
self_randombytes_buf(nonce, NUM2SIZET(size));
|
|
16
|
+
|
|
17
|
+
VALUE n = rb_str_new(nonce, NUM2SIZET(size));
|
|
18
|
+
|
|
19
|
+
free(nonce);
|
|
20
|
+
|
|
21
|
+
return n;
|
|
11
22
|
}
|
|
12
23
|
|
|
13
|
-
static VALUE
|
|
14
|
-
|
|
15
|
-
VALUE retval = Qtrue;
|
|
16
|
-
OlmUtility *this;
|
|
17
|
-
Data_Get_Struct(self, OlmUtility, this);
|
|
24
|
+
static VALUE aead_xchacha20poly1305_ietf_nonce(VALUE self) {
|
|
25
|
+
void * nonce;
|
|
18
26
|
|
|
19
|
-
if
|
|
27
|
+
if ((nonce = malloc(self_crypto_aead_xchacha20poly1305_ietf_NPUBBYTES)) == NULL) {
|
|
28
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
29
|
+
}
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
self_randombytes_buf(nonce, self_crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
|
|
32
|
+
|
|
33
|
+
VALUE n = rb_str_new(nonce, self_crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
|
|
34
|
+
|
|
35
|
+
free(nonce);
|
|
36
|
+
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static VALUE aead_xchacha20poly1305_ietf_keygen(VALUE self) {
|
|
41
|
+
void * key;
|
|
42
|
+
|
|
43
|
+
if ((key = malloc(self_crypto_aead_xchacha20poly1305_ietf_KEYBYTES)) == NULL) {
|
|
44
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
22
45
|
}
|
|
23
46
|
|
|
24
|
-
|
|
47
|
+
self_crypto_aead_xchacha20poly1305_ietf_keygen(key);
|
|
48
|
+
|
|
49
|
+
VALUE k = rb_str_new(key, self_crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
|
|
50
|
+
|
|
51
|
+
free(key);
|
|
52
|
+
|
|
53
|
+
return k;
|
|
25
54
|
}
|
|
26
55
|
|
|
27
|
-
static VALUE
|
|
28
|
-
|
|
56
|
+
static VALUE aead_xchacha20poly1305_ietf_encrypt(VALUE self, VALUE key, VALUE nonce, VALUE plaintext) {
|
|
57
|
+
void * ciphertext;
|
|
58
|
+
unsigned long long ciphertext_len;
|
|
59
|
+
|
|
60
|
+
if (key == Qnil) {
|
|
61
|
+
rb_raise(rb_eStandardError, "must specify a key");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (nonce == Qnil) {
|
|
65
|
+
rb_raise(rb_eStandardError, "must specify a nonce");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (plaintext == Qnil) {
|
|
69
|
+
rb_raise(rb_eStandardError, "must specify plaintext");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ((ciphertext = malloc(RSTRING_LEN(plaintext) + self_crypto_aead_xchacha20poly1305_ietf_ABYTES)) == NULL) {
|
|
73
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
self_crypto_aead_xchacha20poly1305_ietf_encrypt(
|
|
77
|
+
ciphertext,
|
|
78
|
+
(uint64_t *) &ciphertext_len,
|
|
79
|
+
RSTRING_PTR(plaintext),
|
|
80
|
+
RSTRING_LEN(plaintext),
|
|
81
|
+
NULL,
|
|
82
|
+
0,
|
|
83
|
+
NULL,
|
|
84
|
+
RSTRING_PTR(nonce),
|
|
85
|
+
RSTRING_PTR(key)
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
VALUE ct = rb_str_new(ciphertext, ciphertext_len);
|
|
89
|
+
|
|
90
|
+
free(ciphertext);
|
|
91
|
+
|
|
92
|
+
return ct;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE aead_xchacha20poly1305_ietf_decrypt(VALUE self, VALUE key, VALUE nonce, VALUE ciphertext) {
|
|
96
|
+
void * plaintext;
|
|
97
|
+
unsigned long long plaintext_len;
|
|
98
|
+
|
|
99
|
+
if (key == Qnil) {
|
|
100
|
+
rb_raise(rb_eStandardError, "must specify a key");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (nonce == Qnil) {
|
|
104
|
+
rb_raise(rb_eStandardError, "must specify a nonce");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (ciphertext == Qnil) {
|
|
108
|
+
rb_raise(rb_eStandardError, "must specify ciphertext");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if ((plaintext = malloc(RSTRING_LEN(ciphertext))) == NULL) {
|
|
112
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
int status = self_crypto_aead_xchacha20poly1305_ietf_decrypt(
|
|
116
|
+
plaintext,
|
|
117
|
+
(uint64_t *) &plaintext_len,
|
|
118
|
+
NULL,
|
|
119
|
+
RSTRING_PTR(ciphertext),
|
|
120
|
+
RSTRING_LEN(ciphertext),
|
|
121
|
+
NULL,
|
|
122
|
+
0,
|
|
123
|
+
RSTRING_PTR(nonce),
|
|
124
|
+
RSTRING_PTR(key)
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (status != 0) {
|
|
128
|
+
rb_raise(rb_eStandardError, "could not authenticate encrypted message");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
VALUE pt = rb_str_new(plaintext, plaintext_len);
|
|
132
|
+
|
|
133
|
+
free(plaintext);
|
|
134
|
+
|
|
135
|
+
return pt;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk) {
|
|
29
139
|
VALUE curve25519_sk;
|
|
30
|
-
void
|
|
140
|
+
void * pk_ptr, * dec_ptr, * enc_ptr;
|
|
31
141
|
size_t pk_sz, dec_sz, enc_sz, success;
|
|
32
142
|
|
|
33
|
-
if(rb_obj_is_kind_of(ed25519_pk, rb_eval_string("String")) != Qtrue){
|
|
143
|
+
if (rb_obj_is_kind_of(ed25519_pk, rb_eval_string("String")) != Qtrue) {
|
|
34
144
|
rb_raise(rb_eTypeError, "ed25519_pk must be kind of String");
|
|
35
145
|
}
|
|
36
146
|
|
|
37
|
-
pk_sz =
|
|
147
|
+
pk_sz = self_crypto_sign_publickeybytes();
|
|
38
148
|
|
|
39
|
-
if((dec_ptr = malloc(pk_sz)) == NULL){
|
|
149
|
+
if ((dec_ptr = malloc(pk_sz)) == NULL) {
|
|
40
150
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
41
151
|
}
|
|
42
152
|
|
|
43
|
-
success =
|
|
153
|
+
success = self_base642bin(
|
|
44
154
|
dec_ptr,
|
|
45
155
|
pk_sz,
|
|
46
156
|
RSTRING_PTR(ed25519_pk),
|
|
47
157
|
RSTRING_LEN(ed25519_pk),
|
|
158
|
+
NULL, &
|
|
159
|
+
dec_sz,
|
|
48
160
|
NULL,
|
|
49
|
-
|
|
50
|
-
NULL,
|
|
51
|
-
sodium_base64_VARIANT_URLSAFE_NO_PADDING
|
|
161
|
+
self_base64_VARIANT_URLSAFE_NO_PADDING
|
|
52
162
|
);
|
|
53
163
|
|
|
54
|
-
if(success != 0) {
|
|
164
|
+
if (success != 0) {
|
|
55
165
|
free(dec_ptr);
|
|
56
166
|
rb_raise(rb_eTypeError, "could not decode ed25519 public key");
|
|
57
167
|
}
|
|
58
168
|
|
|
59
|
-
if((pk_ptr = malloc(pk_sz)) == NULL){
|
|
169
|
+
if ((pk_ptr = malloc(pk_sz)) == NULL) {
|
|
60
170
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
61
171
|
}
|
|
62
172
|
|
|
63
|
-
success =
|
|
173
|
+
success = self_crypto_sign_ed25519_pk_to_curve25519(
|
|
64
174
|
pk_ptr,
|
|
65
175
|
dec_ptr
|
|
66
176
|
);
|
|
67
177
|
|
|
68
178
|
free(dec_ptr);
|
|
69
179
|
|
|
70
|
-
if(success != 0) {
|
|
180
|
+
if (success != 0) {
|
|
71
181
|
free(pk_ptr);
|
|
72
182
|
rb_raise(rb_eTypeError, "could not convert ed25519 public key");
|
|
73
183
|
}
|
|
74
184
|
|
|
75
|
-
enc_sz =
|
|
185
|
+
enc_sz = self_base64_ENCODED_LEN(pk_sz, self_base64_VARIANT_ORIGINAL_NO_PADDING);
|
|
76
186
|
|
|
77
|
-
if((enc_ptr = malloc(enc_sz)) == NULL){
|
|
187
|
+
if ((enc_ptr = malloc(enc_sz)) == NULL) {
|
|
78
188
|
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
|
79
189
|
}
|
|
80
190
|
|
|
81
|
-
|
|
191
|
+
self_bin2base64(
|
|
82
192
|
enc_ptr,
|
|
83
193
|
enc_sz,
|
|
84
194
|
pk_ptr,
|
|
85
195
|
pk_sz,
|
|
86
|
-
|
|
196
|
+
self_base64_VARIANT_ORIGINAL_NO_PADDING
|
|
87
197
|
);
|
|
88
198
|
|
|
89
199
|
free(pk_ptr);
|
|
@@ -95,49 +205,18 @@ static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
|
|
|
95
205
|
return curve25519_sk;
|
|
96
206
|
}
|
|
97
207
|
|
|
98
|
-
static
|
|
99
|
-
{
|
|
100
|
-
size_t size;
|
|
101
|
-
OlmUtility *this;
|
|
102
|
-
Data_Get_Struct(self, OlmUtility, this);
|
|
103
|
-
|
|
104
|
-
size = olm_sha256_length(this);
|
|
105
|
-
uint8_t buf[size];
|
|
106
|
-
|
|
107
|
-
(void)olm_sha256(this, RSTRING_PTR(data), RSTRING_LEN(data), buf, size);
|
|
108
|
-
|
|
109
|
-
return rb_str_new(buf, size);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static void _free(void *ptr)
|
|
113
|
-
{
|
|
114
|
-
olm_clear_utility(ptr);
|
|
208
|
+
static void _free(void * ptr) {
|
|
115
209
|
free(ptr);
|
|
116
210
|
}
|
|
117
211
|
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
OlmUtility *this;
|
|
121
|
-
VALUE self;
|
|
122
|
-
|
|
123
|
-
self = Data_Wrap_Struct(klass, 0, _free, calloc(1, olm_utility_size()));
|
|
124
|
-
|
|
125
|
-
Data_Get_Struct(self, OlmUtility, this);
|
|
126
|
-
|
|
127
|
-
(void)olm_utility((void *)this);
|
|
128
|
-
|
|
129
|
-
return self;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
void utility_init(void)
|
|
133
|
-
{
|
|
212
|
+
void utility_init(void) {
|
|
134
213
|
VALUE cRubyOLM = rb_define_module("SelfCrypto");
|
|
135
214
|
VALUE cUtil = rb_define_module_under(cRubyOLM, "Util");
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
rb_define_alloc_func(cUtility, _alloc);
|
|
139
|
-
|
|
140
|
-
rb_define_method(cUtility, "sha256", sha256, 1);
|
|
141
|
-
rb_define_method(cUtility, "ed25519_verify", ed25519_verify, 3);
|
|
215
|
+
|
|
142
216
|
rb_define_module_function(cUtil, "ed25519_pk_to_curve25519", ed25519_pk_to_curve25519, 1);
|
|
143
|
-
|
|
217
|
+
rb_define_module_function(cUtil, "random_bytes", random_bytes, 1);
|
|
218
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_keygen", aead_xchacha20poly1305_ietf_keygen, 0);
|
|
219
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_nonce", aead_xchacha20poly1305_ietf_nonce, 0);
|
|
220
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_encrypt", aead_xchacha20poly1305_ietf_encrypt, 3);
|
|
221
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_decrypt", aead_xchacha20poly1305_ietf_decrypt, 3);
|
|
222
|
+
}
|
data/lib/self_crypto/session.rb
CHANGED
data/lib/self_crypto/utility.rb
CHANGED
data/lib/self_crypto/version.rb
CHANGED
data/lib/self_crypto.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
|
2
|
+
|
|
1
3
|
require 'self_crypto/version'
|
|
2
4
|
require 'self_crypto/self_crypto'
|
|
3
5
|
require 'self_crypto/account'
|
|
@@ -7,7 +9,6 @@ require 'self_crypto/olm_message'
|
|
|
7
9
|
require 'self_crypto/message'
|
|
8
10
|
require 'self_crypto/group_message'
|
|
9
11
|
require 'self_crypto/pre_key_message'
|
|
10
|
-
require 'self_crypto/sas'
|
|
11
12
|
require 'self_crypto/utility'
|
|
12
13
|
|
|
13
14
|
module SelfCrypto
|
data/test/spec/test_account.rb
CHANGED
|
@@ -77,34 +77,6 @@ describe "Account" do
|
|
|
77
77
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
describe "#inbound_session" do
|
|
81
|
-
|
|
82
|
-
let(:remote_session){ remote.outbound_session(account.ik['curve25519'], account.otk['curve25519'].values.first) }
|
|
83
|
-
let(:remote_message){ remote_session.encrypt("hello") }
|
|
84
|
-
|
|
85
|
-
it("creates session") { _(account.inbound_session(remote_message)).must_be_kind_of SelfCrypto::Session }
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe "#inbound_session from known remote" do
|
|
90
|
-
|
|
91
|
-
let(:remote_session){ remote.outbound_session(account.ik['curve25519'], account.otk['curve25519'].values.first) }
|
|
92
|
-
let(:remote_message){ remote_session.encrypt("hello") }
|
|
93
|
-
|
|
94
|
-
it("creates session") { _(account.inbound_session(remote_message, remote.ik['curve25519'])).must_be_kind_of SelfCrypto::Session }
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe "#inbound_session from pickled account" do
|
|
99
|
-
|
|
100
|
-
let(:remote_session){ remote.outbound_session(account.ik['curve25519'], account.otk['curve25519'].values.first) }
|
|
101
|
-
let(:remote_message){ remote_session.encrypt("hello") }
|
|
102
|
-
let(:pickled_account){ account.to_pickle("test") }
|
|
103
|
-
let(:unpickled_account){ SelfCrypto::Account.from_pickle(pickled_account, "test") }
|
|
104
|
-
it("creates session") { _(unpickled_account.inbound_session(remote_message, remote.ik['curve25519'])).must_be_kind_of SelfCrypto::Session }
|
|
105
|
-
|
|
106
|
-
end
|
|
107
|
-
|
|
108
80
|
end
|
|
109
81
|
|
|
110
82
|
end
|
data/test/spec/test_util.rb
CHANGED
|
@@ -14,4 +14,16 @@ describe "Util" do
|
|
|
14
14
|
it("should convert"){ _(account.ik['curve25519']).must_equal curve25519_pk }
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
describe "xchacha20_poly1305_itef" do
|
|
18
|
+
message = "something"
|
|
19
|
+
|
|
20
|
+
key = SelfCrypto::Util.aead_xchacha20poly1305_ietf_keygen
|
|
21
|
+
nonce = SelfCrypto::Util.aead_xchacha20poly1305_ietf_nonce
|
|
22
|
+
|
|
23
|
+
ct = SelfCrypto::Util.aead_xchacha20poly1305_ietf_encrypt(key, nonce, message)
|
|
24
|
+
pt = SelfCrypto::Util.aead_xchacha20poly1305_ietf_decrypt(key, nonce, ct)
|
|
25
|
+
|
|
26
|
+
it('should decrypt'){ _(pt).must_equal message}
|
|
27
|
+
end
|
|
28
|
+
|
|
17
29
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: self_crypto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Bevan
|
|
8
8
|
- Cameron Harper
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake-compiler
|
|
@@ -67,7 +67,7 @@ dependencies:
|
|
|
67
67
|
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
69
|
version: '0'
|
|
70
|
-
description:
|
|
70
|
+
description:
|
|
71
71
|
email: ops@selfid.net
|
|
72
72
|
executables: []
|
|
73
73
|
extensions:
|
|
@@ -78,11 +78,6 @@ files:
|
|
|
78
78
|
- ext/self_crypto/account.c
|
|
79
79
|
- ext/self_crypto/extconf.rb
|
|
80
80
|
- ext/self_crypto/omemo.c
|
|
81
|
-
- ext/self_crypto/pk.c
|
|
82
|
-
- ext/self_crypto/pk_decryption.c
|
|
83
|
-
- ext/self_crypto/pk_encryption.c
|
|
84
|
-
- ext/self_crypto/pk_signing.c
|
|
85
|
-
- ext/self_crypto/sas.c
|
|
86
81
|
- ext/self_crypto/self_crypto.c
|
|
87
82
|
- ext/self_crypto/self_crypto.h
|
|
88
83
|
- ext/self_crypto/session.c
|
|
@@ -95,13 +90,9 @@ files:
|
|
|
95
90
|
- lib/self_crypto/olm_error.rb
|
|
96
91
|
- lib/self_crypto/olm_message.rb
|
|
97
92
|
- lib/self_crypto/pre_key_message.rb
|
|
98
|
-
- lib/self_crypto/sas.rb
|
|
99
|
-
- lib/self_crypto/sas_data.rb
|
|
100
93
|
- lib/self_crypto/session.rb
|
|
101
94
|
- lib/self_crypto/utility.rb
|
|
102
95
|
- lib/self_crypto/version.rb
|
|
103
|
-
- test/examples/test_bob_no_answer.rb
|
|
104
|
-
- test/examples/test_exchange.rb
|
|
105
96
|
- test/spec/test_account.rb
|
|
106
97
|
- test/spec/test_util.rb
|
|
107
98
|
- test/unit/test_account_methods.rb
|
|
@@ -109,7 +100,7 @@ homepage: https://github.com/aldgate-ventures/self-crypto-ruby
|
|
|
109
100
|
licenses:
|
|
110
101
|
- Apache-2.0
|
|
111
102
|
metadata: {}
|
|
112
|
-
post_install_message:
|
|
103
|
+
post_install_message:
|
|
113
104
|
rdoc_options: []
|
|
114
105
|
require_paths:
|
|
115
106
|
- lib
|
|
@@ -124,13 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
124
115
|
- !ruby/object:Gem::Version
|
|
125
116
|
version: '0'
|
|
126
117
|
requirements: []
|
|
127
|
-
rubygems_version: 3.
|
|
128
|
-
signing_key:
|
|
118
|
+
rubygems_version: 3.3.15
|
|
119
|
+
signing_key:
|
|
129
120
|
specification_version: 4
|
|
130
121
|
summary: Group end to end encryption for self
|
|
131
122
|
test_files:
|
|
132
|
-
- test/unit/test_account_methods.rb
|
|
133
|
-
- test/examples/test_exchange.rb
|
|
134
|
-
- test/examples/test_bob_no_answer.rb
|
|
135
|
-
- test/spec/test_util.rb
|
|
136
123
|
- test/spec/test_account.rb
|
|
124
|
+
- test/spec/test_util.rb
|
|
125
|
+
- test/unit/test_account_methods.rb
|
data/ext/self_crypto/pk.c
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#include "self_olm/pk.h"
|
|
2
|
-
#include "self_crypto.h"
|
|
3
|
-
|
|
4
|
-
void pk_encryption_init(VALUE cSelfCryptoPK);
|
|
5
|
-
void pk_decryption_init(VALUE cSelfCryptoPK);
|
|
6
|
-
void pk_signing_init(VALUE cSelfCryptoPK);
|
|
7
|
-
|
|
8
|
-
void pk_init(void) {
|
|
9
|
-
VALUE cSelfCrypto = rb_define_module("SelfCrypto");
|
|
10
|
-
VALUE cSelfCryptoPK = rb_define_module_under(cSelfCrypto, "PK");
|
|
11
|
-
|
|
12
|
-
pk_encryption_init(cSelfCryptoPK);
|
|
13
|
-
pk_decryption_init(cSelfCryptoPK);
|
|
14
|
-
pk_signing_init(cSelfCryptoPK);
|
|
15
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
#include <ruby.h>
|
|
2
|
-
#include <stdlib.h>
|
|
3
|
-
#include <self_olm/pk.h>
|
|
4
|
-
#include <self_olm/olm.h>
|
|
5
|
-
#include "self_crypto.h"
|
|
6
|
-
|
|
7
|
-
static void _free(void *ptr) {
|
|
8
|
-
olm_clear_pk_decryption(ptr);
|
|
9
|
-
free(ptr);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static size_t _size(const void *ptr __attribute__((unused))) {
|
|
13
|
-
return olm_pk_decryption_size();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static const rb_data_type_t olm_pk_decryption_type = {
|
|
17
|
-
.wrap_struct_name = "olm_pk_decryption",
|
|
18
|
-
.function = {
|
|
19
|
-
.dmark = NULL,
|
|
20
|
-
.dfree = _free,
|
|
21
|
-
.dsize = _size,
|
|
22
|
-
.reserved = {NULL}
|
|
23
|
-
},
|
|
24
|
-
.data = NULL,
|
|
25
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
static VALUE _alloc(VALUE klass) {
|
|
29
|
-
void *memory = malloc_or_raise(olm_pk_decryption_size());
|
|
30
|
-
return TypedData_Wrap_Struct(klass, &olm_pk_decryption_type, olm_pk_decryption(memory));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static VALUE initialize(int argc, VALUE *argv, VALUE self) {
|
|
34
|
-
OlmPkDecryption *this;
|
|
35
|
-
size_t publicKeyLen;
|
|
36
|
-
char *publicKeyPtr;
|
|
37
|
-
VALUE privateKey;
|
|
38
|
-
TypedData_Get_Struct(self, OlmPkDecryption, &olm_pk_decryption_type, this);
|
|
39
|
-
|
|
40
|
-
rb_scan_args(argc, argv, "01", &privateKey);
|
|
41
|
-
|
|
42
|
-
if (NIL_P(privateKey)) {
|
|
43
|
-
privateKey = get_random(olm_pk_private_key_length());
|
|
44
|
-
} else {
|
|
45
|
-
Check_Type(privateKey, T_STRING);
|
|
46
|
-
if (RSTRING_LEN(privateKey) != olm_pk_private_key_length()) {
|
|
47
|
-
rb_raise(rb_eval_string("ArgumentError"), "private_key has wrong size (must be %lu)", olm_pk_private_key_length());
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
publicKeyLen = olm_pk_key_length();
|
|
52
|
-
publicKeyPtr = malloc_or_raise(publicKeyLen);
|
|
53
|
-
|
|
54
|
-
if (olm_pk_key_from_private(this,
|
|
55
|
-
publicKeyPtr, publicKeyLen,
|
|
56
|
-
RSTRING_PTR(privateKey), RSTRING_LEN(privateKey)) == olm_error()) {
|
|
57
|
-
free(publicKeyPtr);
|
|
58
|
-
raise_olm_error(olm_pk_decryption_last_error(this));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
rb_iv_set(self, "@public_key", rb_str_new(publicKeyPtr, publicKeyLen));
|
|
62
|
-
free(publicKeyPtr);
|
|
63
|
-
|
|
64
|
-
return self;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static VALUE pk_decrypt(VALUE self, VALUE pkMessage) {
|
|
68
|
-
OlmPkDecryption *this;
|
|
69
|
-
size_t plaintextLen;
|
|
70
|
-
char *plaintextPtr;
|
|
71
|
-
VALUE ephemeral, mac, ciphertext, retval;
|
|
72
|
-
TypedData_Get_Struct(self, OlmPkDecryption, &olm_pk_decryption_type, this);
|
|
73
|
-
|
|
74
|
-
ephemeral = rb_funcall(pkMessage, rb_intern("ephemeral_key"), 0);
|
|
75
|
-
Check_Type(ephemeral, T_STRING);
|
|
76
|
-
mac = rb_funcall(pkMessage, rb_intern("mac"), 0);
|
|
77
|
-
Check_Type(mac, T_STRING);
|
|
78
|
-
ciphertext = rb_funcall(pkMessage, rb_intern("cipher_text"), 0);
|
|
79
|
-
Check_Type(ciphertext, T_STRING);
|
|
80
|
-
|
|
81
|
-
plaintextLen = olm_pk_max_plaintext_length(this, RSTRING_LEN(ciphertext));
|
|
82
|
-
plaintextPtr = malloc_or_raise(plaintextLen);
|
|
83
|
-
|
|
84
|
-
plaintextLen = olm_pk_decrypt(this,
|
|
85
|
-
RSTRING_PTR(ephemeral), RSTRING_LEN(ephemeral),
|
|
86
|
-
RSTRING_PTR(mac), RSTRING_LEN(mac),
|
|
87
|
-
RSTRING_PTR(ciphertext), RSTRING_LEN(ciphertext),
|
|
88
|
-
plaintextPtr, plaintextLen);
|
|
89
|
-
if (plaintextLen == olm_error()) {
|
|
90
|
-
free(plaintextPtr);
|
|
91
|
-
raise_olm_error(olm_pk_decryption_last_error(this));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
retval = rb_str_new(plaintextPtr, plaintextLen);
|
|
95
|
-
free(plaintextPtr);
|
|
96
|
-
|
|
97
|
-
return retval;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static VALUE private_key(VALUE self) {
|
|
101
|
-
OlmPkDecryption *this;
|
|
102
|
-
size_t privkeyLen;
|
|
103
|
-
char *privkeyPtr;
|
|
104
|
-
VALUE retval;
|
|
105
|
-
TypedData_Get_Struct(self, OlmPkDecryption, &olm_pk_decryption_type, this);
|
|
106
|
-
|
|
107
|
-
privkeyLen = olm_pk_private_key_length();
|
|
108
|
-
privkeyPtr = malloc_or_raise(privkeyLen);
|
|
109
|
-
|
|
110
|
-
if (olm_pk_get_private_key(this, privkeyPtr, privkeyLen) == olm_error()) {
|
|
111
|
-
free(privkeyPtr);
|
|
112
|
-
raise_olm_error(olm_pk_decryption_last_error(this));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
retval = rb_str_new(privkeyPtr, privkeyLen);
|
|
116
|
-
free(privkeyPtr);
|
|
117
|
-
return retval;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
void pk_decryption_init(VALUE cSelfCryptoPK) {
|
|
121
|
-
VALUE cDecryption = rb_define_class_under(cSelfCryptoPK, "Decryption", rb_cData);
|
|
122
|
-
|
|
123
|
-
rb_define_alloc_func(cDecryption, _alloc);
|
|
124
|
-
|
|
125
|
-
rb_define_attr(cDecryption, "public_key", 1, 0);
|
|
126
|
-
rb_define_method(cDecryption, "initialize", initialize, -1);
|
|
127
|
-
rb_define_method(cDecryption, "decrypt", pk_decrypt, 1);
|
|
128
|
-
rb_define_method(cDecryption, "private_key", private_key, 0);
|
|
129
|
-
}
|