noise-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile +2 -0
- data/README.md +13 -5
- data/lib/noise.rb +1 -0
- data/lib/noise/connection.rb +2 -2
- data/lib/noise/functions/cipher/aes_gcm.rb +9 -3
- data/lib/noise/functions/dh/dh25519.rb +2 -0
- data/lib/noise/functions/hash.rb +7 -3
- data/lib/noise/functions/hash/blake2b.rb +7 -0
- data/lib/noise/pattern.rb +13 -41
- data/lib/noise/state/handshake_state.rb +0 -1
- data/lib/noise/state/symmetric_state.rb +2 -7
- data/lib/noise/utils/string.rb +3 -2
- data/lib/noise/version.rb +1 -1
- data/noise.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c16d9319142dc02bcf5e1524c141aaa99a923942
|
4
|
+
data.tar.gz: b926ad7e994d5387fe48fab254b8f5c0ccb124fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1cafc8d1343cba342d73451a6817001faf4e3298fbc239e6e4efb8d1454087f0826602a73c3c503c9d498eafcfe0aca79fd91bfe3eb2ba401bec13d1b12e9fd
|
7
|
+
data.tar.gz: 40dfacc90d63bb5807dc8ce7b13d01beac299f2a62ef405f98971bf5381e6ff6bf9a2c637eedab26a9d451c95c1715c19991c8ed5014aee0ce28cc426944c3f0
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
# Noise
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby implementation of the Noise Protocol framework(http://noiseprotocol.org/).
|
4
4
|
|
5
|
-
|
5
|
+
## Future Works
|
6
|
+
|
7
|
+
The followings are not supported yet.
|
8
|
+
|
9
|
+
- DH Functions
|
10
|
+
- Curve448
|
11
|
+
- Hash Functions
|
12
|
+
- Blake2s
|
13
|
+
- PSK Mode
|
6
14
|
|
7
15
|
## Installation
|
8
16
|
|
9
17
|
Add this line to your application's Gemfile:
|
10
18
|
|
11
|
-
```
|
12
|
-
gem 'noise'
|
19
|
+
```
|
20
|
+
gem 'noise-ruby'
|
13
21
|
```
|
14
22
|
|
15
23
|
And then execute:
|
@@ -18,7 +26,7 @@ And then execute:
|
|
18
26
|
|
19
27
|
Or install it yourself as:
|
20
28
|
|
21
|
-
$ gem install noise
|
29
|
+
$ gem install noise-ruby
|
22
30
|
|
23
31
|
## Usage
|
24
32
|
|
data/lib/noise.rb
CHANGED
data/lib/noise/connection.rb
CHANGED
@@ -22,8 +22,8 @@ module Noise
|
|
22
22
|
@handshake_started = false
|
23
23
|
@handshake_finished = false
|
24
24
|
@fn = nil
|
25
|
-
@write_message_proc =
|
26
|
-
@read_message_proc =
|
25
|
+
@write_message_proc = ->(payload) { write_message(payload) }
|
26
|
+
@read_message_proc = ->(payload) { read_message(payload) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def prologue=(prologue)
|
@@ -1,19 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'aead'
|
4
|
+
|
3
5
|
module Noise
|
4
6
|
module Functions
|
5
7
|
module Cipher
|
6
8
|
class AesGcm
|
7
9
|
def encrypt(k, n, ad, plaintext)
|
8
|
-
|
10
|
+
mode = AEAD::Cipher.new('AES-256-GCM')
|
11
|
+
cipher = mode.new(k)
|
12
|
+
cipher.encrypt(nonce_to_bytes(n), ad, plaintext)
|
9
13
|
end
|
10
14
|
|
11
15
|
def decrypt(k, n, ad, ciphertext)
|
12
|
-
|
16
|
+
mode = AEAD::Cipher.new('AES-256-GCM')
|
17
|
+
cipher = mode.new(k)
|
18
|
+
cipher.decrypt(nonce_to_bytes(n), ad, ciphertext)
|
13
19
|
end
|
14
20
|
|
15
21
|
def nonce_to_bytes(n)
|
16
|
-
"\00" * 4 +
|
22
|
+
"\00" * 4 + format('%16x', n).htb
|
17
23
|
end
|
18
24
|
end
|
19
25
|
end
|
data/lib/noise/functions/hash.rb
CHANGED
@@ -10,13 +10,17 @@ module Noise
|
|
10
10
|
|
11
11
|
def self.hmac_hash(key, data, digest)
|
12
12
|
# TODO: support for blake2b, blake2s
|
13
|
-
|
13
|
+
if digest.include?('SHA')
|
14
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new(digest), key, data)
|
15
|
+
elsif digest.include?('BLAKE2b')
|
16
|
+
Noise::Functions::Hash::Blake2bHMAC.new(key).update(data).digest
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.create_hkdf_fn(digest)
|
17
|
-
|
21
|
+
lambda do |chaining_key, input_key_material, num_output|
|
18
22
|
hkdf(chaining_key, input_key_material, num_output, digest)
|
19
|
-
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.hkdf(chaining_key, input_key_material, num_outputs, digest)
|
data/lib/noise/pattern.rb
CHANGED
@@ -30,14 +30,20 @@ module Noise
|
|
30
30
|
|
31
31
|
# initiator [Boolean]
|
32
32
|
def required_keypairs(initiator)
|
33
|
+
initiator ? required_keypairs_of_initiator : required_keypairs_of_responder
|
34
|
+
end
|
35
|
+
|
36
|
+
def required_keypairs_of_initiator
|
37
|
+
required = []
|
38
|
+
required << :s if %w[K X I].include?(@name[0])
|
39
|
+
required << :rs if @one_way || @name[1] == 'K'
|
40
|
+
required
|
41
|
+
end
|
42
|
+
|
43
|
+
def required_keypairs_of_responder
|
33
44
|
required = []
|
34
|
-
if
|
35
|
-
|
36
|
-
required << :rs if @one_way || @name[1] == 'K'
|
37
|
-
else
|
38
|
-
required << :rs if @name[0] == 'K'
|
39
|
-
required << :s if @one_way || ['K', 'X'].include?(@name[1])
|
40
|
-
end
|
45
|
+
required << :rs if @name[0] == 'K'
|
46
|
+
required << :s if @one_way || %w[K X].include?(@name[1])
|
41
47
|
required
|
42
48
|
end
|
43
49
|
|
@@ -187,37 +193,3 @@ module Noise
|
|
187
193
|
end
|
188
194
|
end
|
189
195
|
end
|
190
|
-
#
|
191
|
-
# def has_pre_messages(self):
|
192
|
-
# return any(map(lambda x: len(x) > 0, self.pre_messages))
|
193
|
-
#
|
194
|
-
# def get_initiator_pre_messages(self) -> list:
|
195
|
-
# return self.pre_messages[0].copy()
|
196
|
-
#
|
197
|
-
# def get_responder_pre_messages(self) -> list:
|
198
|
-
# return self.pre_messages[1].copy()
|
199
|
-
#
|
200
|
-
# def apply_pattern_modifiers(self, modifiers: List[str]) -> None:
|
201
|
-
# # Applies given pattern modifiers to self.tokens of the Pattern instance.
|
202
|
-
# for modifier in modifiers:
|
203
|
-
# if modifier.startswith('psk'):
|
204
|
-
# try:
|
205
|
-
# index = int(modifier.replace('psk', '', 1))
|
206
|
-
# except ValueError:
|
207
|
-
# raise ValueError('Improper psk modifier {}'.format(modifier))
|
208
|
-
#
|
209
|
-
# if index // 2 > len(self.tokens):
|
210
|
-
# raise ValueError('Modifier {} cannot be applied - pattern has not enough messages'.format(modifier))
|
211
|
-
#
|
212
|
-
# # Add TOKEN_PSK in the correct place in the correct message
|
213
|
-
# if index == 0: # if 0, insert at the beginning of first message
|
214
|
-
# self.tokens[0].insert(0, TOKEN_PSK)
|
215
|
-
# else: # if bigger than zero, append at the end of first, second etc.
|
216
|
-
# self.tokens[index - 1].append(TOKEN_PSK)
|
217
|
-
# self.psk_count += 1
|
218
|
-
#
|
219
|
-
# elif modifier == 'fallback':
|
220
|
-
# raise NotImplementedError # TODO implement
|
221
|
-
#
|
222
|
-
# else:
|
223
|
-
# raise ValueError('Unknown pattern modifier {}'.format(modifier))
|
@@ -109,7 +109,6 @@ module Noise
|
|
109
109
|
temp = message[0...len + offset]
|
110
110
|
message = message[(len + offset)..-1]
|
111
111
|
@rs = @protocol.dh_fn.class.from_public(@symmetric_state.decrypt_and_hash(temp))
|
112
|
-
# @protocol.keypair.load(@symmetric_state.decrypt_and_hash(temp))
|
113
112
|
next
|
114
113
|
when 'ee'
|
115
114
|
@symmetric_state.mix_key(dh_fn.dh(@e[0], @re[1]))
|
@@ -67,13 +67,8 @@ module Noise
|
|
67
67
|
c2 = CipherState.new(cipher: @protocol.cipher_fn)
|
68
68
|
c1.initialize_key(temp_k1)
|
69
69
|
c2.initialize_key(temp_k2)
|
70
|
-
|
71
|
-
|
72
|
-
@protocol.cipher_state_decrypt = c2
|
73
|
-
else
|
74
|
-
@protocol.cipher_state_encrypt = c2
|
75
|
-
@protocol.cipher_state_decrypt = c1
|
76
|
-
end
|
70
|
+
@protocol.cipher_state_encrypt = @protocol.initiator ? c1 : c2
|
71
|
+
@protocol.cipher_state_decrypt = @protocol.initiator ? c2 : c1
|
77
72
|
@protocol.handshake_done
|
78
73
|
[c1, c2]
|
79
74
|
end
|
data/lib/noise/utils/string.rb
CHANGED
data/lib/noise/version.rb
CHANGED
data/noise.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
|
26
|
+
spec.add_runtime_dependency 'aead'
|
26
27
|
spec.add_runtime_dependency 'ecdsa'
|
27
28
|
spec.add_runtime_dependency 'rbnacl'
|
28
|
-
spec.add_runtime_dependency '
|
29
|
+
spec.add_runtime_dependency 'ruby-hmac'
|
29
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noise-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aead
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: ecdsa
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: ruby-hmac
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|