self_crypto 0.0.4 → 0.0.8
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 +2 -9
- data/ext/self_crypto/omemo.c +2 -0
- data/ext/self_crypto/utility.c +119 -3
- data/lib/self_crypto/group_message.rb +2 -0
- data/lib/self_crypto/group_session.rb +2 -0
- data/lib/self_crypto/utility.rb +2 -0
- data/lib/self_crypto/version.rb +3 -1
- data/lib/self_crypto.rb +2 -0
- data/test/spec/test_account.rb +10 -0
- data/test/spec/test_util.rb +29 -0
- data/test/unit/test_account_methods.rb +0 -4
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db3da86cb87d90e72ce0f69a682872a8e2b092b9828e67d1a7641b1952fed59
|
4
|
+
data.tar.gz: e3319c2d1c8f34854500f4f4d723007b89d9c1ac312ae6d271c74d953c22548d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb42f2dd7f586324bd638583c89a867b1858ae4d2da836f15392f851eb36e624f59648c71f5f0fff12fce922cca1b18f37fe2e6019bfda72131af60fa855e3b3
|
7
|
+
data.tar.gz: 770c20da2afea5e5dbd1cf8291584640b1ce1db395bbe916a340c67b429aa1998acfb3aa0d0f56f0f0e05bcd13bd27ef995fcf6866bebb8917c1e80051fcff79
|
data/ext/self_crypto/account.c
CHANGED
@@ -46,24 +46,17 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
46
46
|
}
|
47
47
|
|
48
48
|
if(pickle != Qnil){
|
49
|
-
|
50
49
|
if(olm_unpickle_account(this, RSTRING_PTR(password), RSTRING_LEN(password), RSTRING_PTR(dup_string(pickle)), RSTRING_LEN(pickle)) == olm_error()){
|
51
|
-
|
52
50
|
raise_olm_error(olm_account_last_error(this));
|
53
51
|
}
|
54
|
-
}
|
55
|
-
if(seed != Qnil){
|
52
|
+
} else if(seed != Qnil){
|
56
53
|
if(olm_create_account_derrived_keys(this, RSTRING_PTR(seed), RSTRING_LEN(seed)) == olm_error()){
|
57
|
-
|
58
54
|
raise_olm_error(olm_account_last_error(this));
|
59
55
|
}
|
60
|
-
}
|
61
|
-
else{
|
62
|
-
|
56
|
+
} else {
|
63
57
|
size = olm_create_account_random_length(this);
|
64
58
|
|
65
59
|
if(olm_create_account(this, RSTRING_PTR(get_random(size)), size) == olm_error()){
|
66
|
-
|
67
60
|
raise_olm_error(olm_account_last_error(this));
|
68
61
|
}
|
69
62
|
}
|
data/ext/self_crypto/omemo.c
CHANGED
data/ext/self_crypto/utility.c
CHANGED
@@ -24,6 +24,117 @@ static VALUE ed25519_verify(VALUE self, VALUE data, VALUE key, VALUE signature)
|
|
24
24
|
return retval;
|
25
25
|
}
|
26
26
|
|
27
|
+
static VALUE random_bytes(VALUE self, VALUE size)
|
28
|
+
{
|
29
|
+
void *nonce;
|
30
|
+
|
31
|
+
if((nonce = malloc(NUM2SIZET(size))) == NULL){
|
32
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
33
|
+
}
|
34
|
+
|
35
|
+
randombytes_buf(nonce, NUM2SIZET(size));
|
36
|
+
|
37
|
+
VALUE n = rb_str_new(nonce, NUM2SIZET(size));
|
38
|
+
|
39
|
+
free(nonce);
|
40
|
+
|
41
|
+
return n;
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE aead_xchacha20poly1305_ietf_nonce(VALUE self)
|
45
|
+
{
|
46
|
+
void *nonce;
|
47
|
+
|
48
|
+
if((nonce = malloc(crypto_aead_xchacha20poly1305_ietf_NPUBBYTES)) == NULL){
|
49
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
50
|
+
}
|
51
|
+
|
52
|
+
randombytes_buf(nonce, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
|
53
|
+
|
54
|
+
VALUE n = rb_str_new(nonce, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
|
55
|
+
|
56
|
+
free(nonce);
|
57
|
+
|
58
|
+
return n;
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE aead_xchacha20poly1305_ietf_keygen(VALUE self)
|
62
|
+
{
|
63
|
+
void *key;
|
64
|
+
|
65
|
+
if((key = malloc(crypto_aead_xchacha20poly1305_ietf_KEYBYTES)) == NULL){
|
66
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
67
|
+
}
|
68
|
+
|
69
|
+
crypto_aead_xchacha20poly1305_ietf_keygen(key);
|
70
|
+
|
71
|
+
VALUE k = rb_str_new(key, crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
|
72
|
+
|
73
|
+
free(key);
|
74
|
+
|
75
|
+
return k;
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE aead_xchacha20poly1305_ietf_encrypt(VALUE self, VALUE key, VALUE nonce, VALUE plaintext)
|
79
|
+
{
|
80
|
+
void *ciphertext;
|
81
|
+
unsigned long long ciphertext_len;
|
82
|
+
|
83
|
+
if((ciphertext = malloc(RSTRING_LEN(plaintext) + crypto_aead_xchacha20poly1305_ietf_ABYTES)) == NULL){
|
84
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
85
|
+
}
|
86
|
+
|
87
|
+
crypto_aead_xchacha20poly1305_ietf_encrypt(
|
88
|
+
ciphertext,
|
89
|
+
&ciphertext_len,
|
90
|
+
RSTRING_PTR(plaintext),
|
91
|
+
RSTRING_LEN(plaintext),
|
92
|
+
NULL,
|
93
|
+
0,
|
94
|
+
NULL,
|
95
|
+
RSTRING_PTR(nonce),
|
96
|
+
RSTRING_PTR(key)
|
97
|
+
);
|
98
|
+
|
99
|
+
VALUE ct = rb_str_new(ciphertext, ciphertext_len);
|
100
|
+
|
101
|
+
free(ciphertext);
|
102
|
+
|
103
|
+
return ct;
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE aead_xchacha20poly1305_ietf_decrypt(VALUE self, VALUE key, VALUE nonce, VALUE ciphertext)
|
107
|
+
{
|
108
|
+
void *plaintext;
|
109
|
+
unsigned long long plaintext_len;
|
110
|
+
|
111
|
+
if((plaintext = malloc(RSTRING_LEN(ciphertext))) == NULL){
|
112
|
+
rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
|
113
|
+
}
|
114
|
+
|
115
|
+
int status = crypto_aead_xchacha20poly1305_ietf_decrypt(
|
116
|
+
plaintext,
|
117
|
+
&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
|
+
|
27
138
|
static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
|
28
139
|
{
|
29
140
|
VALUE curve25519_sk;
|
@@ -48,12 +159,12 @@ static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
|
|
48
159
|
NULL,
|
49
160
|
&dec_sz,
|
50
161
|
NULL,
|
51
|
-
|
162
|
+
sodium_base64_VARIANT_URLSAFE_NO_PADDING
|
52
163
|
);
|
53
164
|
|
54
165
|
if(success != 0) {
|
55
166
|
free(dec_ptr);
|
56
|
-
rb_raise(rb_eTypeError, "could not
|
167
|
+
rb_raise(rb_eTypeError, "could not decode ed25519 public key");
|
57
168
|
}
|
58
169
|
|
59
170
|
if((pk_ptr = malloc(pk_sz)) == NULL){
|
@@ -88,7 +199,7 @@ static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
|
|
88
199
|
|
89
200
|
free(pk_ptr);
|
90
201
|
|
91
|
-
curve25519_sk =
|
202
|
+
curve25519_sk = rb_str_new_cstr(enc_ptr);
|
92
203
|
|
93
204
|
free(enc_ptr);
|
94
205
|
|
@@ -140,4 +251,9 @@ void utility_init(void)
|
|
140
251
|
rb_define_method(cUtility, "sha256", sha256, 1);
|
141
252
|
rb_define_method(cUtility, "ed25519_verify", ed25519_verify, 3);
|
142
253
|
rb_define_module_function(cUtil, "ed25519_pk_to_curve25519", ed25519_pk_to_curve25519, 1);
|
254
|
+
rb_define_module_function(cUtil, "random_bytes", random_bytes, 1);
|
255
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_keygen", aead_xchacha20poly1305_ietf_keygen, 0);
|
256
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_nonce", aead_xchacha20poly1305_ietf_nonce, 0);
|
257
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_encrypt", aead_xchacha20poly1305_ietf_encrypt, 3);
|
258
|
+
rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_decrypt", aead_xchacha20poly1305_ietf_decrypt, 3);
|
143
259
|
}
|
data/lib/self_crypto/utility.rb
CHANGED
data/lib/self_crypto/version.rb
CHANGED
data/lib/self_crypto.rb
CHANGED
data/test/spec/test_account.rb
CHANGED
@@ -95,6 +95,16 @@ describe "Account" do
|
|
95
95
|
|
96
96
|
end
|
97
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
|
+
|
98
108
|
end
|
99
109
|
|
100
110
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/reporters'
|
3
|
+
require 'self_crypto'
|
4
|
+
|
5
|
+
reporter_options = { color: true }
|
6
|
+
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)]
|
7
|
+
|
8
|
+
describe "Util" do
|
9
|
+
|
10
|
+
describe "ed25519_pk_to_curve25519" do
|
11
|
+
account = SelfCrypto::Account.from_seed("pA0H92i1hsp1/egmS/tuEho5PpsAaQYrBd0Tj7bvAPI")
|
12
|
+
ed25519_pk = Base64.urlsafe_encode64(Base64.decode64(account.ik['ed25519']), padding: false)
|
13
|
+
curve25519_pk = SelfCrypto::Util.ed25519_pk_to_curve25519(ed25519_pk)
|
14
|
+
it("should convert"){ _(account.ik['curve25519']).must_equal curve25519_pk }
|
15
|
+
end
|
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
|
+
|
29
|
+
end
|
@@ -25,10 +25,6 @@ class TestAccount < Minitest::Test
|
|
25
25
|
assert_equal OlmError::SUCCESS, @state.last_error
|
26
26
|
end
|
27
27
|
|
28
|
-
def test_sign
|
29
|
-
assert_instance_of String, @state.sign("hello")
|
30
|
-
end
|
31
|
-
|
32
28
|
def test_mark_keys_as_published
|
33
29
|
assert_equal @state, @state.mark_keys_as_published
|
34
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Bevan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- test/examples/test_bob_no_answer.rb
|
104
104
|
- test/examples/test_exchange.rb
|
105
105
|
- test/spec/test_account.rb
|
106
|
+
- test/spec/test_util.rb
|
106
107
|
- test/unit/test_account_methods.rb
|
107
108
|
homepage: https://github.com/aldgate-ventures/self-crypto-ruby
|
108
109
|
licenses:
|
@@ -123,12 +124,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.2.5
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: Group end to end encryption for self
|
130
131
|
test_files:
|
131
132
|
- test/unit/test_account_methods.rb
|
132
|
-
- test/examples/test_exchange.rb
|
133
133
|
- test/examples/test_bob_no_answer.rb
|
134
|
+
- test/examples/test_exchange.rb
|
134
135
|
- test/spec/test_account.rb
|
136
|
+
- test/spec/test_util.rb
|