ece 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +26 -2
- data/Rakefile +9 -1
- data/ece.gemspec +1 -1
- data/lib/ece.rb +0 -1
- data/lib/ece/ece.rb +5 -6
- data/lib/ece/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e83a743e5e15a8603358906d330f2152763bcdc48d0bb7793ccbb7a8f30cc86c
|
4
|
+
data.tar.gz: 2251ca33088306a752a496d2e5204658daee8a7c2ef7782f119f6840a8fb7d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e9b83318a4e511dc962b8ab1a42e45b351e2d2961a392ae9096425337b55d7df583d05a54c798cfffa0a3294aba0e6fe1426a3cd47725cad155c548ae2b5f6
|
7
|
+
data.tar.gz: '09ac0852fbb993ffa142a1ccfb5d4de2f7c45ea8dc93c0c4d8fe46f07d8b7c3f8024a62c5314ebd7d6fc4e20293eddc385a2b609a6ce88b79e2496388e42551d'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ECE
|
2
2
|
|
3
|
-
Ruby implementation of encrypted content-encoding.
|
3
|
+
Ruby implementation of encrypted content-encoding.
|
4
4
|
|
5
5
|
https://tools.ietf.org/html/draft-thomson-http-encryption-02
|
6
6
|
|
@@ -34,11 +34,35 @@ data = "Your very private data"
|
|
34
34
|
encrypted_data = ECE.encrypt(data, key: key, salt: salt)
|
35
35
|
```
|
36
36
|
Decrypting:
|
37
|
+
|
37
38
|
```ruby
|
38
39
|
ECE.decrypt(encrypted_data, key: key, salt: salt)
|
39
40
|
```
|
40
41
|
Data can be bytestring as well.
|
42
|
+
|
43
|
+
Encrypting data with elliptical curve Diffie-Hellman (ECDH) key agreement
|
44
|
+
protocol using client keys providing by a [Web Push subscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription/getKey):
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
user_public_key # Provided by the browser, effectively: Random.new.bytes(65)
|
48
|
+
user_auth # Provided by the browser, effectively: Random.new.bytes(16)
|
49
|
+
|
50
|
+
local_curve = OpenSSL::PKey::EC.new("prime256v1")
|
51
|
+
local_curve.generate_key
|
52
|
+
user_public_key_point = OpenSSL::PKey::EC::Point.new(local_curve.group, OpenSSL::BN.new(user_public_key, 2))
|
53
|
+
|
54
|
+
key = local_curve.dh_compute_key(user_public_key_point)
|
55
|
+
server_public_key = local_curve.public_key.to_bn.to_s(2)
|
56
|
+
salt = Random.new.bytes(16)
|
57
|
+
|
58
|
+
encrypted_data = ECE.encrypt(data,
|
59
|
+
key: key,
|
60
|
+
salt: salt
|
61
|
+
server_public_key: server_public_key,
|
62
|
+
user_public_key: user_public_key,
|
63
|
+
auth: user_auth)
|
64
|
+
```
|
65
|
+
|
41
66
|
## Contributing
|
42
67
|
|
43
68
|
Bug reports and pull requests are welcome on GitHub at https://github.com/randomlogin/ece.
|
44
|
-
|
data/Rakefile
CHANGED
data/ece.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
-
spec.add_development_dependency "rake", "~>
|
21
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
22
22
|
spec.add_dependency 'hkdf'
|
23
23
|
end
|
data/lib/ece.rb
CHANGED
data/lib/ece/ece.rb
CHANGED
@@ -19,7 +19,7 @@ class ECE
|
|
19
19
|
def self.hkdf_extract(salt, ikm) #ikm stays for input keying material
|
20
20
|
hmac_hash(salt,ikm)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.get_info(type, client_public, server_public)
|
24
24
|
cl_len_no = [client_public.size].pack('n')
|
25
25
|
sv_len_no = [server_public.size].pack('n')
|
@@ -104,7 +104,7 @@ class ECE
|
|
104
104
|
raise "Block is too small" if buffer.length <= TAG_LENGTH+pad_bytes
|
105
105
|
gcm.auth_tag = buffer[-TAG_LENGTH..-1]
|
106
106
|
decrypted = gcm.update(buffer[0..-TAG_LENGTH-1]) + gcm.final
|
107
|
-
|
107
|
+
|
108
108
|
if params[:auth]
|
109
109
|
padding_length = decrypted[0..1].unpack("n")[0]
|
110
110
|
raise "Padding is too big" if padding_length+2 > decrypted.length
|
@@ -117,7 +117,7 @@ class ECE
|
|
117
117
|
padding = decrypted[1..padding_length]
|
118
118
|
raise "Wrong padding" unless padding = "\x00"*padding_length
|
119
119
|
return decrypted[1..-1]
|
120
|
-
end
|
120
|
+
end
|
121
121
|
end
|
122
122
|
|
123
123
|
def self.encrypt_record(params, counter, buffer, pad=0)
|
@@ -125,7 +125,7 @@ class ECE
|
|
125
125
|
gcm.encrypt
|
126
126
|
gcm.key = params[:key]
|
127
127
|
gcm.iv = generate_nonce(params[:nonce], counter)
|
128
|
-
gcm.auth_data = ""
|
128
|
+
gcm.auth_data = ""
|
129
129
|
padding = ""
|
130
130
|
if params[:auth]
|
131
131
|
padding = [pad].pack('n') + "\x00"*pad # 2 bytes, big endian, then n zero bytes of padding
|
@@ -134,9 +134,8 @@ class ECE
|
|
134
134
|
else
|
135
135
|
record = gcm.update("\x00"+buffer) # 1 padding byte, not fully implemented
|
136
136
|
end
|
137
|
-
enc = record + gcm.final + gcm.auth_tag
|
137
|
+
enc = record + gcm.final + gcm.auth_tag
|
138
138
|
enc
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
141
|
end
|
data/lib/ece/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ece
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shevtsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: hkdf
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
|
91
|
-
rubygems_version: 2.4.8
|
90
|
+
rubygems_version: 3.1.2
|
92
91
|
signing_key:
|
93
92
|
specification_version: 4
|
94
93
|
summary: Ruby implementation of encrypted content-encoding
|