noise-ruby 0.8.4 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +3 -7
- data/lib/noise/connection/base.rb +4 -0
- data/lib/noise/functions/cipher/aes_gcm.rb +4 -0
- data/lib/noise/functions/cipher/cha_cha_poly.rb +2 -2
- data/lib/noise/functions/dh/ed448.rb +18 -4
- data/lib/noise/state/handshake_state.rb +9 -9
- data/lib/noise/version.rb +1 -1
- data/noise.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6e8b4da6da1ab86d95f9712cc5af2fde45c8fb2c6b53f8f76cd4e585c8b509
|
4
|
+
data.tar.gz: 7bbec8a8af754911c1b9ce7026ee21ac98b6af601a40c503e4d4fd03a4679e5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38130604059543fb695227160b59655cc617a29a70abb4d6cac67636fee53b9c7ae78264b6123928842ce1a67ad10a634b7b438d4ec54cf23e48a4e3398aab37
|
7
|
+
data.tar.gz: 0124a47916e35d8267b39336327fc3f496a25068090f6886f92c4a4edf7e4479bb968cd2d78401003821703143bf936aadabd38580146819ab945df981cd0ce1
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -9,15 +9,11 @@ This is required for Lightning Network, layer-2 protocol for bitcoin.
|
|
9
9
|
|
10
10
|
see https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md
|
11
11
|
|
12
|
-
## Future Works
|
13
|
-
|
14
|
-
The followings are not supported yet.
|
15
|
-
|
16
|
-
- DH Functions
|
17
|
-
- Curve448
|
18
|
-
|
19
12
|
## Installation
|
20
13
|
|
14
|
+
This gem needs libsodium and libgoldilocks library.
|
15
|
+
To install these library, see https://github.com/jedisct1/libsodium and https://github.com/otrv4/libgoldilocks
|
16
|
+
|
21
17
|
Add this line to your application's Gemfile:
|
22
18
|
|
23
19
|
```
|
@@ -55,6 +55,7 @@ module Noise
|
|
55
55
|
raise Noise::Exceptions::NoiseHandshakeError unless @handshake_started
|
56
56
|
raise Noise::Exceptions::NoiseHandshakeError if @next_message != :write
|
57
57
|
raise Noise::Exceptions::NoiseHandshakeError if @handshake_finished
|
58
|
+
|
58
59
|
@next_message = :read
|
59
60
|
buffer = +''
|
60
61
|
result = @handshake_state.write_message(payload, buffer)
|
@@ -77,11 +78,13 @@ module Noise
|
|
77
78
|
|
78
79
|
def encrypt(data)
|
79
80
|
raise Noise::Exceptions::NoiseHandshakeError unless @handshake_finished
|
81
|
+
|
80
82
|
@cipher_state_encrypt.encrypt_with_ad('', data)
|
81
83
|
end
|
82
84
|
|
83
85
|
def decrypt(data)
|
84
86
|
raise Noise::Exceptions::NoiseHandshakeError unless @handshake_finished
|
87
|
+
|
85
88
|
@cipher_state_decrypt.decrypt_with_ad('', data)
|
86
89
|
end
|
87
90
|
|
@@ -100,6 +103,7 @@ module Noise
|
|
100
103
|
validate_psk! if psk_handshake?
|
101
104
|
|
102
105
|
raise Noise::Exceptions::NoiseValidationError if valid_keypairs?
|
106
|
+
|
103
107
|
true
|
104
108
|
end
|
105
109
|
|
@@ -12,6 +12,8 @@ module Noise
|
|
12
12
|
cipher.iv = nonce_to_bytes(n)
|
13
13
|
cipher.auth_data = ad
|
14
14
|
cipher.update(plaintext) + cipher.final + cipher.auth_tag
|
15
|
+
rescue OpenSSL::Cipher::CipherError => e
|
16
|
+
raise Noise::Exceptions::EncryptError.new(e)
|
15
17
|
end
|
16
18
|
|
17
19
|
def decrypt(k, n, ad, ciphertext)
|
@@ -21,6 +23,8 @@ module Noise
|
|
21
23
|
cipher.auth_data = ad
|
22
24
|
cipher.auth_tag = ciphertext[-16..-1]
|
23
25
|
cipher.update(ciphertext[0...-16]) + cipher.final
|
26
|
+
rescue OpenSSL::Cipher::CipherError => e
|
27
|
+
raise Noise::Exceptions::DecryptError.new(e)
|
24
28
|
end
|
25
29
|
|
26
30
|
def nonce_to_bytes(n)
|
@@ -10,14 +10,14 @@ module Noise
|
|
10
10
|
cipher = RbNaCl::AEAD::ChaCha20Poly1305IETF.new(String.new(k).force_encoding('ASCII-8BIT'))
|
11
11
|
cipher.encrypt(nonce_to_bytes(n), plaintext, ad)
|
12
12
|
rescue ::RbNaCl::CryptoError => e
|
13
|
-
raise Noise::Exceptions::EncryptError
|
13
|
+
raise Noise::Exceptions::EncryptError.new(e)
|
14
14
|
end
|
15
15
|
|
16
16
|
def decrypt(k, n, ad, ciphertext)
|
17
17
|
cipher = RbNaCl::AEAD::ChaCha20Poly1305IETF.new(String.new(k).force_encoding('ASCII-8BIT'))
|
18
18
|
cipher.decrypt(nonce_to_bytes(n), ciphertext, ad)
|
19
19
|
rescue ::RbNaCl::CryptoError => e
|
20
|
-
raise Noise::Exceptions::DecryptError
|
20
|
+
raise Noise::Exceptions::DecryptError.new(e)
|
21
21
|
end
|
22
22
|
|
23
23
|
def nonce_to_bytes(n)
|
@@ -1,21 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
begin
|
4
|
+
require 'ed448'
|
5
|
+
Ed448.init
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
3
9
|
module Noise
|
4
10
|
module Functions
|
5
11
|
module DH
|
6
12
|
class ED448
|
7
|
-
DHLEN =
|
13
|
+
DHLEN = Ed448::X448::X448_PRIVATE_BYTES
|
14
|
+
|
8
15
|
def generate_keypair
|
9
|
-
|
16
|
+
private_key = SecureRandom.random_bytes(DHLEN)
|
17
|
+
public_key = Ed448::X448.derive_public_key(private_key)
|
18
|
+
Noise::Key.new(private_key, public_key)
|
10
19
|
end
|
11
20
|
|
12
|
-
def dh(
|
13
|
-
|
21
|
+
def dh(private_key, public_key)
|
22
|
+
Ed448::X448.dh(public_key, private_key)
|
14
23
|
end
|
15
24
|
|
16
25
|
def dhlen
|
17
26
|
DHLEN
|
18
27
|
end
|
28
|
+
|
29
|
+
def self.from_private(private_key)
|
30
|
+
public_key = Ed448::X448.derive_public_key(private_key)
|
31
|
+
Noise::Key.new(private_key, public_key)
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
21
35
|
end
|
@@ -46,8 +46,8 @@ module Noise
|
|
46
46
|
# Sets message_patterns to the message patterns from handshake_pattern
|
47
47
|
@message_patterns = @protocol.pattern.tokens.dup
|
48
48
|
|
49
|
-
@protocol.pattern.initiator_pre_messages&.map do |
|
50
|
-
keypair = initiator_keypair_getter.call(
|
49
|
+
@protocol.pattern.initiator_pre_messages&.map do |token|
|
50
|
+
keypair = initiator_keypair_getter.call(token)
|
51
51
|
@symmetric_state.mix_hash(keypair)
|
52
52
|
end
|
53
53
|
|
@@ -57,8 +57,8 @@ module Noise
|
|
57
57
|
@symmetric_state.mix_hash(public_key)
|
58
58
|
end
|
59
59
|
|
60
|
-
@protocol.pattern.responder_pre_messages&.map do |
|
61
|
-
keypair = responder_keypair_getter.call(
|
60
|
+
@protocol.pattern.responder_pre_messages&.map do |token|
|
61
|
+
keypair = responder_keypair_getter.call(token)
|
62
62
|
@symmetric_state.mix_hash(keypair)
|
63
63
|
end
|
64
64
|
end
|
@@ -66,18 +66,18 @@ module Noise
|
|
66
66
|
def expected_message_length(payload_size)
|
67
67
|
has_key = @symmetric_state.cipher_state.key?
|
68
68
|
pattern = @message_patterns.first
|
69
|
-
len = pattern.inject(0) do |
|
69
|
+
len = pattern.inject(0) do |l, token|
|
70
70
|
case token
|
71
71
|
when 'e'
|
72
|
-
|
72
|
+
l += @protocol.dh_fn.dhlen
|
73
73
|
has_key = true if @protocol.psk_handshake?
|
74
74
|
when 's'
|
75
|
-
|
76
|
-
|
75
|
+
l += @protocol.dh_fn.dhlen
|
76
|
+
l += 16 if has_key
|
77
77
|
when 'ee', 'es', 'se', 'ss', 'psk'
|
78
78
|
has_key = true
|
79
79
|
end
|
80
|
-
|
80
|
+
l
|
81
81
|
end
|
82
82
|
len += payload_size
|
83
83
|
len += 16 if has_key
|
data/lib/noise/version.rb
CHANGED
data/noise.gemspec
CHANGED
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.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ed448
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: A Ruby implementation of the Noise Protocol framework(http://noiseprotocol.org/).
|
112
126
|
email:
|
113
127
|
- gen.yamaguchi0@gmail.com
|